一、WebRequest方式
//设置请求接口
var request = (HttpWebRequest)WebRequest.Create(“http://xxx.com/xxx”);
//请求参数
var postData = string.Format(“appId={0}&appScreat={1}&channel={2}”, appId, appScreat, channel);
var data = Encoding.ASCII.GetBytes(postData);
//请求方式
request.Method = “POST”;
//请求头参数设置
request.Headers.Add(“sign”, sign);
request.Headers.Add(“timestamp”, timestamp);
request.Headers.Add(“token”, token);
request.ContentType = “application/x-www-form-urlencoded”;
request.ContentLength = data.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
//结果返回
var response = (HttpWebResponse)request.GetResponse();
//转字符串
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
//转换为json对象
MXCZUserInfoResponse userInfoResponse = JsonConvert.DeserializeObject(responseString);
转载于:https://www.cnblogs.com/bookobe/p/9017001.html