C# .net core使用HttpClient方式调用WebService

// 声明接口入参(多个参数在此累加)

// objData=>对象格式要转成json string

var parameters= new Dictionary<string, string>

{
{ "para1", objData},
{ "para2", "test" },
};
HttpContent httpContent = new FormUrlEncodedContent(parameters);

// contentType对应 webservice提示 如下图
httpContent.Headers.ContentType = new System.Net.Http.Headers.MediaTypeHeaderValue("application/x-www-form-urlencoded");
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = httpClient.PostAsync("https://localhost:44329/WebService1.asmx/HelloWorld", httpContent).Result;
var statusCode = response.StatusCode.ToString();
var result = response.Content.ReadAsStringAsync().Result;
var doc = new XmlDocument();
doc.LoadXml(result);

// xml返回值数据所在标签,替换成你的xml结果标签,如下图

var status = doc.DocumentElement["Status"].InnerXml;

 

C#  .net core使用HttpClient方式调用WebService

 

上一篇:hutool+poi库+excel导出功能


下一篇:进击前端<二> 使用Vue.js开发后台管理平台登录页面