如何获取完整的 POST WebRequest-源代码,因为它出现在 Fiddler/the WinInet Cache
本文关键字:因为 Fiddler Cache WinInet the 源代码 获取 何获取 WebRequest- POST | 更新日期: 2023-09-27 18:35:39
下面的代码示例似乎正在做它应该做的事情,因为小提琴手得到了我想要的数据:
public void SOSampleGet(string url)
{
var webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.Host = "somesitename.abc";
webRequest.KeepAlive = true
webRequest.AutomaticDecompression = DecompressionMethods.GZip DecompressionMethods.Deflate;
System.Net.Cache.HttpRequestCachePolicy a = new
...
string postData = "key1=value1&key2=value2&...
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.ContentLength = byteArray.Length;
Stream dataStream = webRequest.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = webRequest.GetResponse();
dataStream = response.GetResponseStream();
StreamReader reader = new StreamReader(dataStream);
string responseFromServer = reader.ReadToEnd();
}
我的问题:字符串 responceFromServer 缺少源的顶部、中间和底部的重要部分,但是当我查看我使用 Fiddler 提出的请求或检查缓存的源时,这些部分是可见
的他们之后会以某种方式注射吗?还是我需要对源进行两次解码/解密?我不知道我错过了什么
我找到了解决方案:responceFromServer 只有 outerHTML。
我需要安装HtmlAgilityPack来解决这个问题。我只需要更改最后一段,如下所示即可访问所需的 html 数据:
WebResponse response = webRequest.GetResponse();
var temp = response.GetResponseStream();
HtmlDocument Doc = new HtmlDocument();
Doc.Load(temp);
string innerTxt = Doc.DocumentNode.InnerText;