0

构建与使用 JSESSIONID cookie 的站点交互的 ASP.Net 应用程序。我得到的规范说要在每个请求中返回 Cookie。我从登录响应的标头中提取 cookie OK,但是当我尝试在以下请求中使用它时,我得到一个“PlatformNotSupported 错误”显然这是由于安全性中的“改进”。我看到博客谈论编写代理服务器以及创建从 IHttpModule 派生的类。我很困惑。是否有一种直接推荐的编码 HttpWebRequest 的方法,以便我可以传输 Cookie?

StackOverflow 的不常用用户,试图发表评论,失败,所以编辑帖子。代码为:string cookie = "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 集合并将其分配给我原来的登录请求。
SessionIdcookie 返回时,它就会出现在集合中。

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 回答