How to make soap request thru HTTP

本文介绍了一种在HTTP请求中设置不同头部信息的方法,通过具体的C++代码示例展示了如何为SOAP请求设置特定的头部字段。

POST /browser/service1.asmx HTTP/1.1
Host: 192.168.0.13
Content-Type: text/xml; charset=utf-8
Content-Length: length
SOAPAction: "http://tempuri.org/Addition"

<?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>
    <Addition xmlns="http://tempuri.org/">
      <num1>int</num1>
      <num2>int</num2>
    </Addition>
  </soap:Body>
</soap:Envelope>

 

If I understood correctly, you could use a method like below for setting different HTTP headers:
...
void CHTTPClientEngine::SetHeaderL(RHTTPHeaders aHeaders,
                      TInt aHdrField,
                      const TDesC8& aHdrValue)
   {
   RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue);
   CleanupClosePushL(valStr);
   THTTPHdrVal val(valStr);
   aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,
      RHTTPSession::GetTable()), val);
   CleanupStack::PopAndDestroy(); // valStr
   }
...


And call it simply with:
...
   RHTTPHeaders hdr = iTransaction.Request().GetHeaderCollection();
   SetHeaderL(hdr, HTTP::EUserAgent, KUserAgent);
   SetHeaderL(hdr, HTTP::EAccept, KAccept);
   SetHeaderL(hdr, HTTP::EContentType, aContentType);
...

where
const TDesC8& aContentType
RHTTPTransaction      iTransaction;

and constants:
_LIT8(KUserAgent, "MyHTTPClient 1.2.3");
// Accept all content types.
_LIT8(KAccept, "*/*");
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值