用IdHTTPServer控件做http server

c++ builder的一些控件包装好了,直接使用,真的很便利。以下是我实现的用来接收http请求的.

1)启动IdHTTPServer服务

void __fastcall Tfrm_login::FormCreate(TObject *Sender)
{
  IdHTTPServer1->Active=true;
}

2)在IdHTTPServer1CommandGet事件里面添加如下代码就可以接收http的请求了

void __fastcall Tfrm_login::IdHTTPServer1CommandGet(TIdPeerThread *AThread,
      TIdHTTPRequestInfo *RequestInfo, TIdHTTPResponseInfo *ResponseInfo)
{
   //http://127.0.0.1:80/time=20112012&result=1
    AnsiString Str;
    Str=RequestInfo->Document;
    g_logFile.print("HttpServer get string:%s\n",Str);

}

3)

启动程序,在IE浏览器上数输入ip地址,


打印收到的请求的结果


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要连接DataGrid控件与Sql Server数据库,需要以下步骤: 1. 添加SqlConnection对象并设置连接字符串。连接字符串包含有关数据库服务器和其他连接参数的信息。例如: ```csharp SqlConnection connection = new SqlConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;"); ``` 2. 创建SqlCommand对象并设置SQL查询。例如: ```csharp SqlCommand command = new SqlCommand("SELECT * FROM MyTable", connection); ``` 3. 创建SqlDataAdapter对象并使用SqlCommand对象执行查询。例如: ```csharp SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); ``` 4. 将DataTable对象绑定到DataGrid控件。例如: ```csharp dataGrid1.ItemsSource = dataTable.DefaultView; ``` 完整代码示例: ```csharp using System.Data.SqlClient; using System.Windows; using System.Windows.Controls; using System.Data; namespace WpfApp1 { public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); SqlConnection connection = new SqlConnection("Data Source=myServerAddress;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;"); SqlCommand command = new SqlCommand("SELECT * FROM MyTable", connection); SqlDataAdapter adapter = new SqlDataAdapter(command); DataTable dataTable = new DataTable(); adapter.Fill(dataTable); dataGrid1.ItemsSource = dataTable.DefaultView; } } } ``` 注意:在实际应用程序中,连接字符串应该存储在配置文件中,并且不应在代码中硬编码。此外,还要确保在查询中使用正确的表名和列名。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值