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

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
// 声明接口入参(多个参数在此累加)
 
// 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;

  

 

posted @   大脑过载  阅读(766)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· DeepSeek 开源周回顾「GitHub 热点速览」
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· AI与.NET技术实操系列(二):开始使用ML.NET
· 单线程的Redis速度为什么快?
点击右上角即可分享
微信分享提示