2个回答
展开全部
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(URL);
req.Timeout = 15000; //超时时间
req.CookieContainer = new CookieContainer();
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows 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();
req.Timeout = 15000; //超时时间
req.CookieContainer = new CookieContainer();
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows 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();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
public string Get(string URI)
{
HttpWebRequest request = WebRequest.Create(URI) as HttpWebRequest;
request.Method = "GET";
request.KeepAlive = false;
-- request.CookieContainer = this.Cookies;
-- request.Proxy = this.Proxy;
-- request.Timeout = this.Timeout;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, this.En);
string srcString = reader.ReadToEnd();
response.Close();
responseStream.Close();
reader.Close();
return srcString;
}
{
HttpWebRequest request = WebRequest.Create(URI) as HttpWebRequest;
request.Method = "GET";
request.KeepAlive = false;
-- request.CookieContainer = this.Cookies;
-- request.Proxy = this.Proxy;
-- request.Timeout = this.Timeout;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
Stream responseStream = response.GetResponseStream();
StreamReader reader = new StreamReader(responseStream, this.En);
string srcString = reader.ReadToEnd();
response.Close();
responseStream.Close();
reader.Close();
return srcString;
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询