0

次のコードを作成しましたが、私が知る限り正常に動作するはずですか? Cookie をまったく受信していません。Wire Shark で再確認したところ、Cookie が返されています... これは Windows Phone 7 で開発されています。

            byte[] content = GetLoginRequestContent(username, password);

        CookieContainer cookieContainer = new CookieContainer();
        HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(LoginUri);
        httpWebRequest.ContentType = AuthContentType;
        httpWebRequest.Method = "POST";
        httpWebRequest.Headers["referer"] = LoginRequestReferer;
        httpWebRequest.CookieContainer = cookieContainer;
        httpWebRequest.Headers[HttpRequestHeader.ContentLength] = content.Length.ToString();



        httpWebRequest.BeginGetRequestStream(async1 =>
        {
            using (Stream stream = httpWebRequest.EndGetRequestStream(async1))
                stream.Write(content, 0, content.Length);
            httpWebRequest.BeginGetResponse(async2 =>
            {
                HttpWebResponse rep = (HttpWebResponse)httpWebRequest.EndGetResponse(async2);
                CookieCollection cookies = rep.Cookies;
                using (Stream stream = rep.GetResponseStream())
                using (StreamReader sr = new StreamReader(stream))
                {
                    String contentX = sr.ReadToEnd();
                    //if blah blah
                }
            }, null);
        }, null);
4

1 に答える 1

2

Cookie がHttpOnlyでマークされている場合 (セッション Cookie の場合によくあることです)、セキュリティ上の理由から、クライアント側のスクリプトでそれらにアクセスすることはできません。これはクライアントに送信され、クライアントは後続のリクエストでサーバーに再送信しますが (Cookie コンテナーがある場合)、クライアントでその値を読み取ることはできません。

于 2012-06-14T06:25:55.397 に答える