请求外部接口
BaseHttpResponse res = new BaseHttpResponse();
string postUrl = "接口地址"
string postJson = JsonConvert.SerializeObject(param);
string responseStr = "";
try
{
HttpClientHelp helper = new HttpClientHelp();
responseStr = helper.PostDataSCMA(postUrl, postJson);
ReturnModel responseData = JsonConvert.DeserializeObject<ReturnModel>(responseStr);
}
catch (Exception ex)
{
}
public string PostDataSCMA(string url, string postData)
{
UTF8Encoding encoding = new UTF8Encoding();
byte[] data = encoding.GetBytes(postData);
HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
myRequest.Method = "POST";
myRequest.ContentType = "application/json";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
return content;
}