不是代码的问题,而是你这个请求的URL是否有效
用
if(httpWebResponse.StatusCode == HttpStatusCode.OK)
{
//请求正确
}
else
{
//请求错误,关闭会话
}
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL)req.Timeout = 15000//超时时间
req.CookieContainer = new CookieContainer()
req.UserAgent = "Mozilla/4.0 (compatibleMSIE 7.0Windows NT 5.2.NET CLR 1.1.4322.NET CLR 2.0.50727)"
req.ContentType = "multipart/form-data"
WebResponse resp = req.GetResponse()
StreamReader sr = new StreamReader(resp.GetResponseStream(), Encoding.UTF8)
sReturn = sr.ReadToEnd().Trim()
resp.Close()
sr.Close()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)