私はここで何が間違っているのか把握するのに苦労しています。私はログイン情報を送信している、私は正しい値でヘッダーのセットクッキーを見ることができますが、クッキーコレクションは満たされていません。Set-Cookieヘッダー(no-redirect)にもかかわらず、HttpWebResponse.Cookiesが空です
これはHTTPSです。ログインは自動的にリダイレクトされますが、この問題のトラブルシューティングを試みるにはAllowAutoRedirect = falseで無効にしました。
このスクリーンショットでは、デバッグ情報が簡単に表示され、クッキーが設定されるはずです。 httpWebRequest.Cookieを新しいCookieCollectionに設定しています。
HttpWebRequest httpRequest;
CookieContainer reqCookies = new CookieContainer();
string url = "https://example.com";
string[] email = user.Split('@');
email[0] = System.Web.HttpUtility.UrlEncode(email[0]);
user = email[0] + "@" + email[1];
pass = System.Web.HttpUtility.UrlEncode(pass);
string postData = "email=" + user + "&password=" + pass;
byte[] byteData = Encoding.UTF8.GetBytes(postData);
httpRequest = (HttpWebRequest)WebRequest.Create(url);
httpRequest.Method = "POST";
httpRequest.Referer = url;
httpRequest.CookieContainer = reqCookies;
httpRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/18.0.1003.1 Safari/535.19";
httpRequest.Accept = "text/html, application/xhtml+xml, */*";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.ContentLength = byteData.Length;
using (Stream postStream = httpRequest.GetRequestStream())
{
postStream.Write(byteData, 0, byteData.Length);
postStream.Close();
}
httpRequest.AllowAutoRedirect = false;
HttpWebResponse b = (HttpWebResponse)httpRequest.GetResponse();
ここ
はのSet-Cookieヘッダーの値がある...なんてこった... http://www.yahoo.comへの接続とまったく同じコードを試してみましたが、クッキーは私のコレクションの中に入れています
s = 541E2101-B768-45C8-B814-34A00525E50F;ドメイン= example.com;パス= /; バージョン= 1
正しいドメイン名がサーバーから設定されていることを確認してください。それはdomain.comか.domain.comか、どちらも異なっています。あなたのコードをASP.NETに投稿できますか? –