Delphi中进行HTTP POST wsdl使用的SOAP服务  
官方Delphi 学习QQ群: 682628230(三千人)
频道

Delphi中进行HTTP POST wsdl使用的SOAP服务


uses

  ..., IdGlobalProtocols, IdHTTP, IdSSLOpenSSL;


procedure TForm3.Button2Click(Sender: TObject);

var

  SoapMsg: string;

  PostData, ResponseData: TStream;

begin

  // buid up this string however you want (XML library, etc) ...

  SoapMsg :=

    '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tem="http://tempuri.org/">' +

    '  <soapenv:Header/>' +

    '  <soapenv:Body>' +

    '    <tem:Consulta>' +

    '      <!--Optional:-->' +

    '      <tem:expresionImpresa><![CDATA[?re=LSO1306189R5&rr=GACJ940911ASA&tt=4999.99&id=e7df3047-f8de-425d-b469-37abe5b4dabb]]></tem:expresionImpresa>' +

    '    </tem:Consulta>' +

    '  </soapenv:Body>' +

    '</soapenv:Envelope>';


  ResponseData := TMemoryStream.Create;

  try

    PostData := TStringStream.Create(SoapMsg, TEncoding.UTF8);

    try

      IdHTTP1.IOHandler := IdSSLIOHandlerSocketOpenSSL1;


      IdHTTP1.HTTPOptions := IdHTTP1.HTTPOptions + [hoNoProtocolErrorException, hoWantProtocolErrorContent];


      IdHTTP1.Request.ContentType := 'text/xml';

      IdHTTP1.Request.Charset := 'utf-8';

      IdHTTP1.Request.Accept := 'text/xml';

      IdHTTP1.Request.CacheControl := 'no-cache';

      IdHTTP1.Request.CustomHeaders.Values['SOAPAction'] := 'http://tempuri.org/IConsultaCFDIService/Consulta';


      IdHTTP1.Post('https://consultaqr.facturaelectronica.sat.gob.mx/ConsultaCFDIService.svc?wsdl', PostData, ResponseData);

    finally

      PostData.Free;

    end;


    Memo1.Lines.BeginUpdate;

    try

      Memo1.Lines.Add(Format('Response Code: %d', [IdHTTP1.ResponseCode]));

      Memo1.Lines.Add(Format('Response Text: %s', [IdHTTP1.ResponseText]));

      ResponseData.Position := 0;

      ReadStringsAsCharset(ResponseData, Memo1.Lines, IdHTTP1.Response.Charset);

    finally

      Memo1.Lines.EndUpdate;

    end;

  finally

    ResponseData.Free;

  end;

end;



推荐分享
图文皆来源于网络,内容仅做公益性分享,版权归原作者所有,如有侵权请告知删除!
 

Copyright © 2014 DelphiW.com 开发 源码 文档 技巧 All Rights Reserved
晋ICP备14006235号-8 晋公网安备 14108102000087号

执行时间: 0.046813011169434 seconds