public ContentResult UseHttpWebRquust(string url,string param) { HttpWebResponse response = null; Stream stream = null; StreamReader streamReader = null; Stream responseStream = null; string jsontext = string.Empty; try { HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; request.Method = "POST"; request.Accept = "*/*"; request.ContentType = "multipart/byteranges";//根据需要设置请求内容类型 request.Timeout = 50000; request.KeepAlive = true;//建立永久链接 request.ProtocolVersion = HttpVersion.Version10; //request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 2.0.50727;)"; //ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3; byte[] data = Encoding.Default.GetBytes(param); request.ContentLength = data.Length; using (stream = request.GetRequestStream()) { stream.Write(data, 0, data.Length); } response = request.GetResponse() as HttpWebResponse; responseStream = response.GetResponseStream(); streamReader = new StreamReader(responseStream, Encoding.UTF8); SmsResult smsResult = Newtonsoft.Json.JsonConvert.DeserializeObject<SmsResult>(jsontext); result = smsResult.resultCode; if (responseStream != null) { responseStream.Close(); } if (streamReader != null) { streamReader.Close(); } if (stream != null) { stream.Close(); } //关闭stream的顺序要正确 } catch (System.Exception ex) { return Content(result.ToString()); } return Content(result.ToString()); }