delphi idhttp如何使用?

wanghp1230 2009-08-14 11:18:53
哪位大哥用过idhttp的??主要怎么样向服务器端传输数据的,然后数据保存在数据库中方面的?谢谢
...全文
1880 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
tonykk2008 2011-07-26
  • 打赏
  • 举报
回复
good~
like8115 2010-01-24
  • 打赏
  • 举报
回复
hh
啥都得学呀 2009-08-26
  • 打赏
  • 举报
回复
var
I: Integer;
MyStream: TMemoryStream;
ReadBool: BOOLEAN;
URLList: TstringList;
TempIdHttp: Tidhttp;

TempIdHttp.post(URLList[i], OutValues, MyStream);
参数1 POST的URL地址 OUTVALUES是要传输的数据如(a=1,多个可以用stringlist的add添加)
MyStream 数据传输后返回的结果

啥都得学呀 2009-08-26
  • 打赏
  • 举报
回复
if ReadBool then
begin
//ShowMessage('ok');
MyStream.Position := 0;
MyStream.Size;
LoadResult.LoadFromStream(MyStream);
MyStream.Free;
FreeAndNil(URLList);
ExceptPro;
end
else
begin
MyStream.Free;
FreeAndNil(URLList);
ExceptPro;
//ShowMessage('Err');
end;
啥都得学呀 2009-08-26
  • 打赏
  • 举报
回复
TempIdHttp := TIdHTTP.Create(nil);
with TempIdHttp do begin
//OnWorkBegin := IdHTTP1WorkBegin;
//OnWork := idHTTP1Work;
//OnWorkEnd := IdHTTP1WorkEnd;
//OnStatus := IdHTTP1Status;
TempIdHttp.ReadTimeOut := 15000;
//Name := 'http' + IntToStr(i);
TempIdHttp.HandleRedirects := False;
//TempIdHttp.OnRedirect := MyRedirect;
TempIdHttp.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)';
TempIdHttp.Request.ContentType := 'application/x-www-form-urlencoded; Charset=UTF-8';
//TempIdHttp.Request.Host := 'member1.taobao.com';
TempIdHttp.Request.Connection := 'Keep-Alive';
TempIdHttp.Request.Accept := 'text/html, */*';
if OutValues = nil then
TempIdHttp.Request.ContentLength := 0
else
TempIdHttp.Request.ContentLength := Length(OutValues.Text);

try
try
TempIdHttp.post(URLList[i], OutValues, MyStream);
ReadBool := true;
break;
except
ReadBool := false;
end;
finally
FreeAndNil(TempIdHttp);
end;
end;
wintergoes 2009-08-14
  • 打赏
  • 举报
回复

procedure TForm1.Button1Click(Sender: TObject);
var
slPost: TStringList;
begin
slPost := TStringList.Create;
try
slPost.Add('username=abcd');
slPost.Add('age=32');
// .....
IdHTTP1.Post('http://url.com', slPost);
finally
slpost.free;
end;
end;



服务端可以ASP\ASP.NET\JSP等等接收数据
sdycy 2009-08-14
  • 打赏
  • 举报
回复
我做过一个项目,客户端是用的DELPHI IDHTTP 后台是用的JAVA servlet. 实际上就是模拟hTTP post提交

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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