public static string UseWebService(string url,Dictionary<string,string> dic)
{
try
{
HttpClient client = new HttpClient();
var jsonCon =string.Join("&",dic.Select(d=>$"{d.Key}={HttpUtility.UrlEncode(d.Value)}"));
HttpContent httpContent = new StringContent(jsonCon, Encoding.UTF8, "application/x-www-form-urlencoded");
var Res = client.PostAsync(url, httpContent).Result;
var result = Res.Content.ReadAsStringAsync().Result;
return result;
}
catch (Exception e)
{
return "";
}
}
调用方法
var url = "http://。。/Service.asmx/方法名称";
var dic=new Dictionary<string,string>{{"参数名称",参数值}};
string result = Http.UseWebService(url, dic);
来源:oschina
链接:https://my.oschina.net/u/4340310/blog/4280985