调用
测试接口为 http://***/webservice/interOuterService/pushData
1.Http 调用接口(如果接口参数是复杂对象,该方法失效 例如数组)
HttpClient client = new HttpClient();
var jsonCon = "{receiveModelXml:\"" + xmlResult + "\"}";
HttpContent httpContent = new StringContent(jsonCon, Encoding.UTF8, "application/json");
var url = "http://***/webservice/interOuterService/pushData ";
var Res = client.PostAsync(url, httpContent).Result;
var sdssdasdaas = Res.Content.ReadAsStringAsync();
注意事项
1.参数中一定要写好入参名称,否则报错 参数未找到
2.如果接口需要的是xml文件。可以将xml转成string 然后以json传输(格式转换见)
3.如果ContentType采用 "application/x-www-form-urlencoded"
形式的http请求(如果没问题 不需要修改)
需要对web.config文件进行修改,在<system.web>块内修改:
如果是运行时版本4.0, 添加下面一段内容即可(亲测)
<httpRuntime requestValidationMode="2.0"/>
如果仍有问题,继续修改
<webServices>
<protocols>
<add name="HttpPost"/>
<add name="HttpGet"/>
</protocols>
</webServices>
2.soap1.2协议的http请求(必须使用该方法的情况:接口需要传对象而不是字符串)
var param4 = "<soap:Envelope xmlns:soap=\"http://www.w3.org/2003/05/soap-envelope\" xmlns:tem=\"http://tempuri.org/\"><soap:Header/><soap:Body><tem:SyncIncrementOrgToI8Async><tem:models><tem:OrgModel><tem:OCode>qw</tem:OCode><tem:OCBo>21111Z</tem:OCBo><tem:OName>13</tem:OName><tem:OrgType>Y</tem:OrgType><tem:CBoo></tem:CBoo><tem:Bopomofo></tem:Bopomofo><tem:CodeValue></tem:CodeValue><tem:OMemo>13</tem:OMemo><tem:I