http 调用soap webservice

来源:互联网 发布:sqlite for mac 编辑:程序博客网 时间:2024/06/05 17:39

delphi

使用控件idhttp,post xml字符串,获取返回结果


有用记得回复一下,满足我小小的虚荣心

//下面是是调用AAA的接口,返回的也是xml字符串

//这个调了一整天,网上没找到完整的资料,一些属性猜了又猜,还用抓包工具不断调,才搞定,程序员有时也要踩狗屎才行啊

很多人都习惯用httprio控件,不过我用的是delphi7, 然后这个控件就不稳定了,要到Delphi2010后的版本才能稳定使用

不然一些启用了数据保护的电脑就会报内存错误,(右键 我的电脑 => 属性 => 高级 选项卡 在性能那点设置 => 数据执行保护 ),要禁用数据保护才能跑. 



delphi
<span style="font-family:Microsoft YaHei;font-size:14px;">var  IdHTTP1: TIdHTTP;  Params: TStrings;  html: string;begin  IdHTTP1 := TidHTTp.create(self);  Params := TStringList.Create;  IdHTTP1.AllowCookies := True;  IdHTTP1.HTTPOptions := [hoKeepOrigProtocol];  IdHTTP1.ProtocolVersion := pv1_1;  IdHTTP1.Request.Accept := '*/*';  IdHTTP1.Request.ContentType := 'text/xml; charset=utf-8';   IdHTTP1.Request.UserAgent := 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; Trident/4.0)';  IdHTTP1.Request.ContentLength := -1;  IdHTTP1.Request.Connection := 'Keep-Alive';  IdHTTP1.Request.CacheControl := 'no-cache';  IdHTTP1.Request.CustomHeaders.Add('SOAPAction: "http://tempuri.org/AAA"');  Params.Text := '<?xml version="1.0" encoding="utf-8"?>'    + '<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" '    + 'xmlns:xsd="http://www.w3.org/2001/XMLSchema" '    + 'xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">'    + '  <soap:Body>'    + '    <AAA xmlns="http://tempuri.org/" />'    + '  </soap:Body>'    + '</soap:Envelope>';  try    params.SaveToFile(ExtractFilePath(ParamStr(0)) + 'my.txt');    html := Utf8ToAnsi(IdHTTP1.Post('http://192.168.2.26/Services/App/WebService.asmx', Params));  except    //showmessage('error');  end;  memo2.Text := IdHTTP1.ResponseText;  IdHTTP1.Disconnect;  FreeAndNil(IdHTTP1);  FreeAndNil(Params);end;</span>



0 0