を提供していない: - 私はFirefoxで改ざんデータプラグインを使用する場合.NET HttpWebResponseの私はにWebResponseからLocationヘッダを取得する問題を抱えているLocationヘッダー
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";
は私が欲しいものを得る:
場所= http://www.xxxxx.sk?i9=3522a42d0207
しかしHttpWebResponse.Headers
を見ると(受信ヘッダの90%は、Firefoxの場合と同様であるが)、このヘッダが含まれていない
私は設定しようとしました。 Expect
私はそのヘッダーを提供するようにサーバーを強制するが、エラー417が出る。
私はさらに要求のために必要なのですか、その中にセッションIDが存在することを、そのヘッダであるたい理由(ウェブサイトは、二重のセキュリティを持っている - URLでクッキー+セッションIDの)私はない何
デフォルトでHttpWebRequest
がリダイレクトに従うので、サーバーが301/302ステータスコードを送信すると、Locationヘッダーを使用してリソースをフェッチするための新しい要求が発行されることを理解しています。したがって、この最終的なリソースがフェッチされると、レスポンスにはLocationヘッダーが存在しなくなります。しかし、AllowAutoRedirect
をに設定した場合、偽と表示されるのはなぜですか?
EDITED:ヘッダ:
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
}
はなぜ使うのですが、全くヘッダを「期待」?もう1つのオプションは、cookieContainerが要求前に適切に初期化されていないことです。 – bestsss
Hmm。バグのように聞こえる。 system.netトレースログを取得してpastebinに置くことはできますか?ここに指示がありますhttp://ferozedaud.blogspot.com/2009/08/tracing-with-systemnet.html – feroze
私はExpectを普通に使うつもりはありませんでしたが、試してみる価値がありました。 –