delphi实现post请求,前提头部先引用IDHttp组件
var
fhttpRequest: TIdHTTP;
PostData : TStringStream;
tmpStr : String;
begin
fhttpRequest := TIdHTTP.Create(nil);
fhttpRequest.HandleRedirects := True;//允许头转向
fhttpRequest.ReadTimeout := 5000;//请求超时设置
fhttpRequest.Request.ContentType := 'application/x-www-form-urlencoded';//设置内容类型为json
PostData := TStringStream.Create('');
//PostData.Position := 0;//将流位置置为0
PostData.WriteString('encode=773130f7236b15405c9497c19bf24a038ba04197f017bfb0dd66d455bcb75e9e580');
PostData.WriteString('302a5d177cae445ae6c97be24a74344c2cade3dee0015cda9e3ef05a71a9b32409f7d026e633a8125d8d62298aa1a5d35c50e40dc316a07b355d4f70b712b73f37befe911824a78ec556556951d2bf76ec4944e73cbc3b2b88ada31a85b09');
tmpStr := fhttpRequest.Post('http://10.32.8.34:8081/phis/EncodeServlet',PostData); //tmpStr是提交后返回的数据
fhttpRequest.free;
PostData.Free;
Result:=tmpStr;
end;
网友评论