C# 如何用HttpWebReques获得HTTP响应的数据包???

RT~喔耶得了再追分
2025-02-17 16:52:59
推荐回答(4个)
回答1:

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();

回答2:

GetResponse()方法

回答3:

一楼正确

回答4:

楼上正解。 不过你要获取数据包要干啥呢?