webservice 报文post传递

http接口报文如何发送
参考:http://bits00.iteye.com/blog/1634698
实际上,使用LR还有一种测试WebService的方式,就是采用HTTP协议,因为WebService是构建在HTTP协议之上的,因此可以WEB虚拟用户协议中的web_custom_request来构造WebService的请求。

Action()
{
   web_reg_save_param("Response","LB=", "RB=", LAST);
   web_add_header("SOAPAction", "SampleMethod");
   lr_start_transaction("REQ");
   web_custom_request("Sample_Request","Method=POST",
         "Mode=HTML",
         "RecContentType=text/xml",
         "EncType=text/xml; charset=utf-8",
         "URL=http://example.com:1234/sample/",
         "Body=<Envelope xmlns=\"http://example.com/sample\">\n"
               "   <Header/>\n"
               "   <Body>\n"
               "      <price><id>001</id></price>\n"
               "   </Body>\n"
               "</Envelope>",
   "LAST");
   lr_end_transaction("REQ", LR_AUTO);
   lr_output_message("Response is : %s\n", lr_eval_string("{Response}"));
   return 0;
}

自己的代码
请求的url:     http://esbpre.******.com:9106/SuNingServiceWeb/mb
消息:    
<MbfService xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><input1><MbfHeader>
  <ServiceCode>SuperKeyMgmt</ServiceCode>
  <Operation>queryBindRelationforPhone</Operation>
  <AppCode>EPP</AppCode>
  <UId>361cbc5c2812465f85f9911b791f87d92ba765e466cc4d2a</UId>
  <AuthId>EPP;hI35ixh@tR%j</AuthId>
</MbfHeader><MbfBody><YLReq>
  <transactionId>SNYFB001201507211513431000147944</transactionId>
  <account>0000000000002017066</account>
  <reqAcct>SNYFB001</reqAcct>
  <reqKey>12qw!@</reqKey>
</YLReq></MbfBody></input1></MbfService>
代码:
Action()
{ lr_start_transaction("cloud");
web_reg_find("Fail=NotFound",
"Search=All",
"Text=<resCode>8006</resCode> ",
LAST);

   web_add_header("Content-Type","application/soap+xml; charset=utf-8");

    web_custom_request("web_custom_request",
    "URL=http://esbpre.****.com:9106/SuNingServiceWeb/mb",
    "Method=POST",
    "TargetFrame=",
    "Resource=0",
    "Referer=",
    "Body=<MbfService xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><input1><MbfHeader>"   
      "<ServiceCode>SuperKeyMgmt</ServiceCode>"
      "<Operation>queryBindRelationforPhone</Operation>"
      "<AppCode>EPP</AppCode>"
      "<UId>d00883250a074ee984edb677cc731153a8d79add06224006</UId>"
      "<AuthId>EPP;hI35ixh@tR%j</AuthId>"
    "</MbfHeader><MbfBody><YLReq>"
      "<transactionId>SNYFB001201406110850101000038468</transactionId>"
      "<account>{ACCOUNT}</account>"//6009151496
      "<reqAcct>SNYFB001</reqAcct>"
      "<reqKey>12qw!@</reqKey>"
    "</YLReq></MbfBody></input1></MbfService>",
    LAST);

   lr_end_transaction("cloud", LR_AUTO);
   return 0;
}

说明:
http接口的html消息发送,1.选择post方式,2.加头web_add_header("");声明后面要传html消息;3.body内填写完整的html消息。

猜你喜欢

转载自124358959.iteye.com/blog/2229603