在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
/// <summary> /// 转发Post请求 /// </summary> /// <param name="curRequest">要转发的请求</param> /// <param name="url">转发到的Url地址</param> public static string ForwardRequest(HttpRequest curRequest, string url) { byte[] inputBytes; int inputStreamLength; using (var inputStream = curRequest.InputStream) { inputStreamLength = Convert.ToInt32(inputStream.Length); inputBytes = new byte[inputStreamLength + 1]; inputStream.Read(inputBytes, 0, inputStreamLength); inputStream.Close(); } //构造请求 var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "POST"; request.ContentType = curRequest.ContentType; request.ContentLength = curRequest.ContentLength; using (var requestStream = request.GetRequestStream()) { requestStream.Write(inputBytes, 0, inputStreamLength); requestStream.Close(); } string result = string.Empty; using (WebResponse response = request.GetResponse()) { if (response != null) { using (Stream stream = response.GetResponseStream()) { using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); } } } } return result; }
|
请发表评论