当前位置: 首页 > 知识库问答 >
问题:

HTTPRequest标头不在Wireshark中

伊温书
2023-03-14

我设置了一些HTTP请求头,如下所示:

        this.Url = new Uri(u);
        HttpWebRequest http = (HttpWebRequest)WebRequest.Create(Url);
        WebResponse response = http.GetResponse();

        //headers
        http.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0\r\n";
        http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
        http.Headers.Add("Accept-Encoding", "gzip,deflate,sdch'r'n");
        http.Headers.Add("Accept-Language", "en-US,en;q=0.9\r\n");
        http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n");

我是这样捕捉它们的:

            for (count = 0; count < http.Headers.Keys.Count; count++)
        {
            headerKey = http.Headers.Keys[count];
            headerValue = http.Headers[headerKey];

            if (headerValue != null)
            {
                if (headerKey == null)
                {
                    requestbuffer.Append(headerValue);
                    requestbuffer.Append(Newline); 
                }
                else
                {
                    requestbuffer.Append(headerKey + ": " + headerValue);
                    requestbuffer.Append(Newline);
                }
            }
        }

当我运行测试工具时,一切似乎都很好:

  • 主持人:domain.com

但是,在Wireshark和Fiddler中,仅发送以下标头:

  • 获取/HTTP/1.1

知道为什么吗?

共有2个答案

华凡
2023-03-14

是的,您正在发送请求后设置标头。

试试这个:

    //headers
    http.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0\r\n";
    http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
    http.Headers.Add("Accept-Encoding", "gzip,deflate,sdch'r'n");
    http.Headers.Add("Accept-Language", "en-US,en;q=0.9\r\n");
    http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n");

    //Added diesposal of response too
    using (WebResponse response = http.GetResponse())
    {
    }
卢知
2023-03-14

您试图在调用http.GetResponse()后添加标题。那是在请求被发送之后。将其更改为:

this.Url = new Uri(u);
HttpWebRequest http = (HttpWebRequest)WebRequest.Create(Url);

//headers
http.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0\r\n";
http.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8\r\n";
http.Headers.Add("Accept-Encoding", "gzip,deflate,sdch'r'n");
http.Headers.Add("Accept-Language", "en-US,en;q=0.9\r\n");
http.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.3\r\n");

using (WebResponse response = http.GetResponse())
{
    // Do whatever
}

(请注意,您确实应该处理响应。)

 类似资料:
  • 以及一些我熟悉的头,如accept、accept-encoding等。 我正在使用.NET4.0来发出HTTP/HTTPS请求。当尝试添加这些以冒号开头的标头时,第一个项目会引发错误: 错误消息: 这是否意味着我需要升级到较新的.NET版本? 提前道谢。

  • 我尝试使用HttpRequest(dart:html)执行POST请求,以调用一个使用基本身份验证保护的rest服务。 在执行POST调用之前,执行选项调用(由dart:html发出),而不使用authorization标头。这导致401未经授权的响应。 请求标头: Accept:*/* Accept-Encoding:gzip、deflate、SDCH Accept-Control-Reques

  • Wireshark(前称Ethereal)是一个网络封包分析软件。网络封包分析软件的功能是撷取网络封包,并尽可能显示出最为详细的网络封包资料。 网络封包分析软件的功能可想像成 "电工技师使用电表来量测电流、电压、电阻" 的工作 - 只是将场景移植到网络上,并将电线替换成网络线。 在过去,网络封包分析软件是非常昂贵,或是专门属于营利用的软件。Ethereal的出现改变了这一切。在GNUGPL通用许可

  • 当使用Akka HttpRequest将请求发送给一个actor时,我无法识别响应。actor将处理收到的每条消息,但它不知道哪个请求用于获得该响应。有什么方法可以识别每个请求并匹配响应呢? 注意:我没有服务器来再次发送请求体的任何部分。 预先感谢

  • Wireshark has support for the Ceph protocol and it will be shipped in the 1.12.1 release. Using To use the Wireshark dissector you must build it from git, the process is outlined in great detail in th

  • wireshark解析插件,用于解析google protobuf协议。 最新的版本支持运行时模式,只需要提供proto消息定义文件即可。