0

JSESSIONIDCookieを使用するサイトと対話するASP.Netアプリを構築します。私が与えられた仕様は、リクエストごとにCookieを返すように言っています。ログイン応答のヘッダーからCookieを抽出しましたが、次のリクエストで使用しようとすると、「PlatformNotSupportedエラー」が発生します。これは、セキュリティの「改善」が原因であると思われます。プロキシサーバーの作成とIHttpModuleから派生したクラスの作成について話しているブログを見たことがあります。混乱しています。Cookieを転送できるようにHttpWebRequestをコーディングするための簡単な推奨方法はありますか?

StackOverflowの使用頻度の低いユーザーがコメントを投稿しようとしましたが、失敗したため、投稿を編集しています。コードは次のとおりです。stringcookie="JSESSIONID =" + Session ["SessionId"]。ToString();

        if(Request.Cookies["JSESSIONID"]==null)
        {

            //Request.Headers.Add("Cookie",cookie);//PlatformNotSupportedError
            HttpCookie cook = new HttpCookie("JSESSIONID", Session["SessionId"].ToString());
            Request.Cookies.Add(cook);


        } //The prev login response had the cookie in the header not in the cookies collection so I was trying to send back the same way. ASP.net app at this stage. Will be service after get it going. Thx Bob
4

1 に答える 1

1

それを見つけた。Cookie コレクションを作成し、それを元のログイン要求に割り当てる必要があったことがわかりました。Cookie は、返されたときにコレクションに表示されます
SessionId

byte[] bytes = Encoding.UTF8.GetBytes(xml);
  CookieContainer cookies = new CookieContainer();
  HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
  request.CookieContainer = cookies;
  request.Credentials = new NetworkCredential(user, password);
  request.Method = "POST";
  request.ContentLength = bytes.Length;
  request.ContentType = "text/xml";
  using (Stream requestStream = request.GetRequestStream())
  {
    requestStream.Write(bytes, 0, bytes.Length);
  }
于 2012-08-19T21:31:25.773 に答える