//接收
Stream stream = HttpContext.Current.Request.InputStream;
byte[] getByte = new byte[stream.Length];
stream.Read(getByte, 0, getByte.Length);
string postStr = Encoding.UTF8.GetString(getByte);
//请求
string url = "";
HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(url);
webrequest.Method = "post";
webrequest.ContentType = "application/json;charset=UTF-8";
byte[] postByte = Encoding.UTF8.GetBytes(postStr);
webrequest.ContentLength = postByte.Length;
Stream stream1 = webrequest.GetRequestStream();
stream1.Write(postByte, 0, postByte.Length);
stream1.Close();
HttpWebResponse response;
try
{
response = (HttpWebResponse)webrequest.GetResponse();
}
catch (WebException ex)
{
response = (HttpWebResponse)ex.Response;//返回远程服务器报告回来的错误
}
StreamReader sr = new StreamReader(response.GetResponseStream());
string getStr = sr.ReadToEnd();
C#的远程post接收与请求
最新推荐文章于 2023-07-30 00:01:00 发布