接口代码:
[HttpPost]
public void PostTest()
{
string content = Request.Content.ReadAsStringAsync().Result;
}
请求代码:
/// <param name="address">接口地址</param>
/// <param name="data">Json格式字符串参数</param>
public static string SendRequestPost(string address, string data)
{
WebRequest request = null;
WebResponse response = null;
Stream requestStream = null;
StreamReader responseStream = null;
string responseString = null;
string method = "POST";
string contentType = "application/json";
byte[] bytes = Encoding.UTF8.GetBytes(data);
request = WebRequest.Create(address);
request.ContentType = contentType;
request.Method = method;
request.Timeout = 300000;
request.ContentLength = bytes.Length;
requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Close();
response = request.GetResponse();
responseStream = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
responseString = responseStream.ReadToEnd();
response.Close();
return responseString;
}