gpt4 book ai didi

header - .NET HttpWebResponse 不提供位置 header

转载 作者:行者123 更新时间:2023-12-01 04:14:04 26 4
gpt4 key购买 nike

我在从 WebResponse 获取 Location header 时遇到问题:

private CookieContainer _cookieContainer = new CookieContainer();
...
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);

webRequest.Method = "POST";
webRequest.Referer = "www.xxxxx.sk";
webRequest.Proxy = GetSystemProxy();
webRequest.AllowAutoRedirect = false;
webRequest.CookieContainer = _cookieContainer;
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.KeepAlive = false;
//webRequest.Expect = "Location";

当我在 Firefox 中使用篡改数据插件时 - 我得到了我想要的:

位置=http://www.xxxxx.sk?i9=3522a42d0207

但是看着 HttpWebResponse.Headers不包含此 header (尽管 90% 的接收 header 与 firefox 的情况相同)

我试过设置。 Expect强制服务器向我提供该 header ,但我收到错误 417 预期失败。

我想要该 header 的原因是,其中有一个 session ID,我确实需要进一步的请求(网站具有双重安全性 - URL 中的 cookie + session ID)

我不明白的是默认情况下 HttpWebRequest 将遵循重定向 ,因此如果服务器发送 301/302 状态代码,将发出新请求以使用 Location header 获取资源。因此,一旦获取了最终资源,响应中将不再有 Location header 。但如果我设置 AllowAutoRedirect ,为什么没有出现标题?

编辑: 标题:
Mozilla request headers:


Host=prihlasenie.azet.sk
User-Agent=Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.13) Gecko/20101203 Firefox/3.6.13
Accept=text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language=en-us,en;q=0.5
Accept-Encoding=gzip,deflate
Accept-Charset=ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive=115
Connection=keep-alive
Referer=http://www.azet.sk/
Content-Type=application/x-www-form-urlencoded
Content-Length=64
POSTDATA=form%5Busername%5D=yyyyyyyyyy&form%5Bpassword%5D=zzzzzzzzzz
--
Mozilla response headers:



Status=Found - 302
Date=Fri, 14 Jan 2011 13:12:37 GMT
Server=Apache
Pragma=no-cache
Expires=Fri, 14 Jan 2011 13:12:37 +0000
Cache-Control=post-check=0, pre-check=0, no-cache, must-revalidate
Set-Cookie=AZetSecId=3a2f118910; expires=Fri, 28-Jan-2011 13:12:37 GMT; path=/; domain=.azet.sk
Location=http://www.azet.sk/?i9=6ffcf488a877
Vary=User-Agent,Accept-Encoding
X-Served-By=prihlasenieweb-04
Content-Encoding=gzip
Content-Length=1124
Keep-Alive=timeout=15, max=82
Connection=Keep-Alive
Content-Type=text/html

--
------------------------------------------------
---
HttpWebRequest headers:

{Referer: http://www.xxxx.sk
Content-Type: application/x-www-form-urlencoded
Host: prihlasenie.xxxx.sk
Content-Length: 59
Expect: 100-continue
Connection: Close
}

and I'm doing:

byte[] paramBytes = Encoding.ASCII.GetBytes(postParameters);
webRequest.ContentLength = paramBytes.Length;

using (Stream requestStream = webRequest.GetRequestStream())
{
requestStream.Write(paramBytes, 0, paramBytes.Length);
}
---
HttpWebResponse headers:

{Pragma: no-cache
Vary: User-Agent,Accept-Encoding
X-Served-By: prihlasenieweb-05
Connection: close
Content-Length: 2113
Cache-Control: post-check=0, pre-check=0, no-cache, must-revalidate
Content-Type: text/html
Date: Thu, 13 Jan 2011 20:56:21 GMT
Expires: Thu, 13 Jan 2011 20:56:21 +0000
Set-Cookie: xxxxSecId=b425262c2e; expires=Thu, 27-Jan-2011 20:56:21 GMT; path=/; domain=.xxxx.sk
Server: Apache
}

最佳答案

问题在于 cookie 的初始化,因为网络服务器可能依赖它们来启动身份验证过程。

额外注意:请在标签中添加 (http) cookie(“http-headers”覆盖它但它太全局标签)

关于header - .NET HttpWebResponse 不提供位置 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4683721/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com