<small id='sp291'></small><noframes id='sp291'>

<tfoot id='sp291'></tfoot>
    <bdo id='sp291'></bdo><ul id='sp291'></ul>

        <i id='sp291'><tr id='sp291'><dt id='sp291'><q id='sp291'><span id='sp291'><b id='sp291'><form id='sp291'><ins id='sp291'></ins><ul id='sp291'></ul><sub id='sp291'></sub></form><legend id='sp291'></legend><bdo id='sp291'><pre id='sp291'><center id='sp291'></center></pre></bdo></b><th id='sp291'></th></span></q></dt></tr></i><div id='sp291'><tfoot id='sp291'></tfoot><dl id='sp291'><fieldset id='sp291'></fieldset></dl></div>
        <legend id='sp291'><style id='sp291'><dir id='sp291'><q id='sp291'></q></dir></style></legend>
      1. C# - 连接:在 HttpWebRequest 期间未发送 keep-alive 标头

        时间:2023-10-25

          • <bdo id='uHqSC'></bdo><ul id='uHqSC'></ul>
            <legend id='uHqSC'><style id='uHqSC'><dir id='uHqSC'><q id='uHqSC'></q></dir></style></legend>

            <small id='uHqSC'></small><noframes id='uHqSC'>

            <tfoot id='uHqSC'></tfoot>

              <i id='uHqSC'><tr id='uHqSC'><dt id='uHqSC'><q id='uHqSC'><span id='uHqSC'><b id='uHqSC'><form id='uHqSC'><ins id='uHqSC'></ins><ul id='uHqSC'></ul><sub id='uHqSC'></sub></form><legend id='uHqSC'></legend><bdo id='uHqSC'><pre id='uHqSC'><center id='uHqSC'></center></pre></bdo></b><th id='uHqSC'></th></span></q></dt></tr></i><div id='uHqSC'><tfoot id='uHqSC'></tfoot><dl id='uHqSC'><fieldset id='uHqSC'></fieldset></dl></div>
                <tbody id='uHqSC'></tbody>
                1. 本文介绍了C# - 连接:在 HttpWebRequest 期间未发送 keep-alive 标头的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在尝试使用我的 HttpWebRequest 发送以下标头:

                  I'm trying to send to send the following header with my HttpWebRequest:

                  连接:保持活动

                  但是,标头永远不会发送.Fiddler2 显示,每当我在 Google Chrome 中请求页面时,都会发送标头.但是,我的应用程序出于某种原因拒绝发送此标头.

                  However, the header is never sent. Fiddler2 is showing that whenever I request the page in Google Chrome, the header is sent. However, my application refuses to send this header for some reason.

                  我已将 KeepAlive 属性设置为 true(默认情况下它是 true),但标头仍未发送.

                  I have set the KeepAlive property to true (it's true by default anyway), yet the header still does not get sent.

                  我正在尝试使用多个 HttpWebRequest 发送此标头,但它们基本上都是这样的:

                  I am trying to send this header with multiple HttpWebRequests, but they all basically look like this:

                  HttpWebRequest logIn6 = (HttpWebRequest)WebRequest.Create(new Uri(responseFromLogIn5));
                  logIn6.CookieContainer = cookies;
                  logIn6.KeepAlive = true;
                  logIn6.Referer = "https://login.yahoo.com/config/login?.src=spt&.intl=us&.lang=en-US&.done=http://football.fantasysports.yahoo.com/";
                  logIn6.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1";
                  logIn6.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
                  logIn6.Headers.Add("Accept-Encoding:gzip,deflate,sdch");
                  logIn6.Headers.Add("Accept-Language:en-US,en;q=0.8");
                  logIn6.Headers.Add("Accept-Charset:ISO-8859-1,utf-8;q=0.7,*;q=0.3");
                  logIn6.AllowAutoRedirect = false;
                  
                  HttpWebResponse logIn6Response = (HttpWebResponse)logIn6.GetResponse();
                  string responseFromLogIn6 = logIn6Response.GetResponseHeader("Location");
                  
                  cookies.Add(logIn6Response.Cookies);
                  
                  logIn6Response.Close();
                  

                  有人知道我必须做什么来确保发送此标头吗?

                  Does anyone know what I have to do to make sure this header is sent?

                  来自 Chrome 的 Fiddler2 Raw:

                  Fiddler2 Raw From Chrome:

                  GET xxx HTTP/1.1
                  Host: accounts.google.com
                  Connection: keep-alive
                  Referer: https://login.yahoo.com/config/login?.src=spt&.intl=us&.lang=en-US&.done=http://football.fantasysports.yahoo.com/
                  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1
                  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                  Accept-Encoding: gzip,deflate,sdch
                  Accept-Language: en-US,en;q=0.8
                  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
                  Cookie: xxx
                  
                  HTTP/1.1 302 Moved Temporarily
                  Set-Cookie: xxx
                  Set-Cookie: xxx
                  Location: xxx
                  Content-Type: text/html; charset=UTF-8
                  P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/bin/answer.py?hl=en&answer=151657 for more info."
                  Date: Sat, 17 Sep 2011 22:27:09 GMT
                  Expires: Sat, 17 Sep 2011 22:27:09 GMT
                  Cache-Control: private, max-age=0
                  X-Content-Type-Options: nosniff
                  X-Frame-Options: SAMEORIGIN
                  X-XSS-Protection: 1; mode=block
                  Content-Length: 2176
                  Server: GSE
                  

                  我的应用程序中的 Fiddler2 Raw:

                  Fiddler2 Raw From My Application:

                  GET xxx HTTP/1.1
                  Referer: https://login.yahoo.com/config/login?.src=spt&.intl=us&.lang=en-US&.done=http://football.fantasysports.yahoo.com/
                  User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.220 Safari/535.1
                  Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
                  Accept-Encoding: gzip,deflate,sdch
                  Accept-Language: en-US,en;q=0.8
                  Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
                  Host: accounts.google.com
                  
                  HTTP/1.1 302 Moved Temporarily
                  Location: xxx
                  Content-Type: text/html; charset=UTF-8
                  Date: Sun, 18 Sep 2011 00:05:40 GMT
                  Expires: Sun, 18 Sep 2011 00:05:40 GMT
                  Cache-Control: private, max-age=0
                  X-Content-Type-Options: nosniff
                  X-Frame-Options: SAMEORIGIN
                  X-XSS-Protection: 1; mode=block
                  Content-Length: 573
                  Server: GSE
                  

                  我正在尝试让第二个 Fiddler2 原始信息看起来像第一个 Fiddler2 原始信息.

                  I'm trying to get the second Fiddler2 raw information to look like the first Fiddler2 raw information.

                  推荐答案

                  我也遇到了同样的问题:Connection: Keep-Alive header is not sent except the first request, and the server如果它丢失,我访问不会给我正确的响应.所以,这是我对这个问题的解决方法:

                  I've had the same issue: The Connection: Keep-Alive header is not sent except the first request, and the server I accessed won't give me the correct response if it is missing. So, here are my workarounds to this issue:

                  首先将 HttpWebRequest 实例的 ProtocolVersion 属性设置为 HttpVersion.Version10.除了 http 命令将变为 GET xxx HTTP/1.0 之外,它可以工作并且只使用公共 API.

                  First is set the ProtocolVersion property of HttpWebRequest instance to HttpVersion.Version10. Except the http command will become GET xxx HTTP/1.0, it works and uses only the public API.

                  第二种方式使用反射修改HttpWebRequest实例的内部属性ServicePoint.HttpBehaviour,如下:

                  The second way uses the reflection to modify the internal property ServicePoint.HttpBehaviour of HttpWebRequest instance, like this:

                  var req = (HttpWebRequest)WebRequest.Create(someUrl);
                  
                  var sp = req.ServicePoint;
                  var prop = sp.GetType().GetProperty("HttpBehaviour", 
                                          BindingFlags.Instance | BindingFlags.NonPublic);
                  prop.SetValue(sp, (byte)0, null);
                  
                  req.GetResponse().Close();
                  

                  希望这会有所帮助.

                  这篇关于C# - 连接:在 HttpWebRequest 期间未发送 keep-alive 标头的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:如何设置 httpexpires 和 cachecontrol 标头 下一篇:缓存控制:在 IIS7 + ASP.NET MVC 中,没有存储、必须重新验证未发送到客户端浏览器

                  相关文章

                  <tfoot id='y48x9'></tfoot>
                2. <small id='y48x9'></small><noframes id='y48x9'>

                    <bdo id='y48x9'></bdo><ul id='y48x9'></ul>

                      <legend id='y48x9'><style id='y48x9'><dir id='y48x9'><q id='y48x9'></q></dir></style></legend>
                    1. <i id='y48x9'><tr id='y48x9'><dt id='y48x9'><q id='y48x9'><span id='y48x9'><b id='y48x9'><form id='y48x9'><ins id='y48x9'></ins><ul id='y48x9'></ul><sub id='y48x9'></sub></form><legend id='y48x9'></legend><bdo id='y48x9'><pre id='y48x9'><center id='y48x9'></center></pre></bdo></b><th id='y48x9'></th></span></q></dt></tr></i><div id='y48x9'><tfoot id='y48x9'></tfoot><dl id='y48x9'><fieldset id='y48x9'></fieldset></dl></div>