Post 方式
=================================
var
Param:TStringList;
RStream:TStringStream;
begin
Param:=TStringList.Create;
RStream:=TStringStream.Create('');
Param.Add('username=showlee000');
Param.Add('normModPsp=********');
Param.Add('mem_pass=true');
IdHTTP1.Post('Http://URL',Param,RStream);
memo1.Text:=RStream.DataString;
====================================
另一代码
procedure PostDemo;
var
IdHttp : TIdHTTP;
Url : string;//请求地址
ResponseStream : TStringStream; //返回信息
ResponseStr : string;
RequestList : TStringList; //请求信息
RequestStream : TStringStream;
begin
//创建IDHTTP控件
IdHttp := TIdHTTP.Create(nil);
//TStringStream对象用于保存响应信息
ResponseStream := TStringStream.Create('');
RequestStream := TStringStream.Create('');
RequestList := TStringList.Create;
try
Url := 'http://f.youdao.com/?path=fanyi&vendor=fanyiinput';
try
//以列表的方式提交参数
RequestList.Add('text=love');
IdHttp.Post(Url,RequestList,ResponseStream);
//以流的方式提交参数
RequestStream.WriteString('text=love');
IdHttp.Post(Url,RequestStream,ResponseStream);
except
on e : Exception do
begin
ShowMessage(e.Message);
end;
end;
//获取网页返回的信息
ResponseStr := ResponseStream.DataString;
//网页中的存在中文时,需要进行UTF8解码
ResponseStr := UTF8Decode(ResponseStr);
finally
IdHttp.Free;
RequestList.Free;
RequestStream.Free;
ResponseStream.Free;
end;
end;
======================================
Get 方式
===========================================
idHttp1.Request.CustomHeaders.Text :=
'Accept: image/jpeg, application/x-ms-application, image/gif, application/xaml+xml, image/pjpeg, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*'+
#13+#10+'Referer:http://url'+
#13+#10+'Accept-Language: zh-CN' +
#13+#10+'User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Trident/5.0)'+
#13+#10+'Accept-Encoding: gzip, deflate'+
#13+#10+'Host: ***'+
#13+#10+'Connection: Keep-Alive'+
#13+#10+'Authorization: Basic *****=';
IdHTTP1.get('http://url');
====================================
另一代码
procedure GetDemo;
var
IdHttp : TIdHTTP;
Url : string;//请求地址
ResponseStream : TStringStream; //返回信息
ResponseStr : string;
begin
//创建IDHTTP控件
IdHttp := TIdHTTP.Create(nil);
//TStringStream对象用于保存响应信息
ResponseStream := TStringStream.Create('');
try
//请求地址
Url := 'http://dict.youdao.com/';
try
IdHttp.Get(Url,ResponseStream);
except
on e : Exception do
begin
ShowMessage(e.Message);
end;
end;
//获取网页返回的信息
ResponseStr := ResponseStream.DataString;
//网页中的存在中文时,需要进行UTF8解码
ResponseStr := UTF8Decode(ResponseStr);
finally
IdHttp.Free;
ResponseStream.Free;
end;
end;