多线程使用IDHttp Post网页,求思路?

tgtt 2005-08-29 09:13:06
我要用idHttp控件同时Post10个网页,求比较方便可行的解决方案?如有代码例子更好,非常感谢!
...全文
216 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
chaopi 2005-08-30
  • 打赏
  • 举报
回复
//.cpp中的线程描述
_fastcall TMyThread::TMyThread(void):TThread(true)
{
FreeOnTerminate=true;
Resume();
}

_fastcall TMyThread::~TMyThread()
{
delete HTTP;
}

//声明线程
void __fastcall TMyThread::Execute()//线程功能
{
for(int i=1;i<4;i++)
Form1->Memo1->Text=Form1->Memo1->Text+IntToStr(i)+"我得到了参数--我的线程\r\n";
}
void __fastcall TForm1::Button2Click(TObject *Sender)//执行线程
{
MyThread=new TMyThread();
MyThread->FreeOnTerminate=true;
HTTP = new TIdHttp(NULL);//这句可能有问题,但反正就是new个idHttp啦
}
//.h中的线程类定义
//声明线程
class TMyThread:public TThread
{
public:
__fastcall TMyThread(void);
__fastcall ~TMyThread();
TIdHttp *HTTP;
private:
void __fastcall Execute(void);
};

//可以在.h的窗体类定义中加入
TMyThread *MyThread[10];//声明一个自己的线程

然后用时候就for(int i=0;i<10;i++) MyThread[i] = new TMyThread();
思路大概如此,上面程序没有验证过,应该N多错误,看思路好了:P
我不懂电脑 2005-08-30
  • 打赏
  • 举报
回复
多线程和单线程用的方法一样,只是new多个线程而已。
mylai911 2005-08-29
  • 打赏
  • 举报
回复
//使用Indy9.0
//Unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "Unit1.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
TForm1 *Form1;
//---------------------------------------------------------------------------
__fastcall TForm1::TForm1(TComponent* Owner)
: TForm(Owner)
{
}
//---------------------------------------------------------------------------
DWORD CALLBACK MyPhone(void *p)
{
try
{
TIdHTTP* MyHttp=new TIdHTTP(Application);
String data="user=test";
String url="http://www.163.com/";
TStrings *Source=new TStringList();
Source->Add(data);
String body=MyHttp->Post(url,Source);
}
catch(...){}
return 0;
}
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
try
{
DWORD ThreadID;
HANDLE hthread=CreateThread(0,0,MyPhone,0,0,&ThreadID);
}
catch(...){}
}
//---------------------------------------------------------------------------

1,317

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder 网络及通讯开发
社区管理员
  • 网络及通讯开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧