Windows Phone 8的WebResponse会跳过set-cookie headers吗?

本文关键字:set-cookie headers Phone WebResponse Windows | 更新日期: 2023-09-27 17:50:59

我正在构建一个Windows Phone 8应用程序,我遇到了一些奇怪的行为,我希望在座的人有一些经验。

我正在阅读一个使用正常HttpWebRequest的网站,并期待一个cookie作为响应。然而,不知何故,我没有得到Set-cookie头回到我的WebResponse。我在WPF下创建了相同的功能,它正常工作-在响应中返回Set-cookie标头。

我也试着看响应的CookieContainer,但它也是空的。

这是我使用的代码。注意:同一段代码(没有异步的东西)在WPF中正确工作,并返回Set-Cookie。如果有必要,我也可以贴出来:

  HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.mysite.com/login");
  request.Method = HttpMethod.Post;
  request.AllowAutoRedirect = false;//normally there is a redirect in place
  postData = "username=1234&password=2345";
  var data = Encoding.UTF8.GetBytes(postData);
  request.ContentType = "application/x-www-form-urlencoded";
  request.ContentLength = data.Length;
using (var stream = await Task.Factory.FromAsync<Stream>(request.BeginGetRequestStream, request.EndGetRequestStream, null))
    {
        await stream.WriteAsync(data, 0, data.Length);
        stream.Close();
    }
                using (var response = await Task.Factory.FromAsync<WebResponse>(request.BeginGetResponse, request.EndGetResponse, null))
    {
         return response.Headers["set-cookie"];
    }

因此,我得到一些响应头(如内容类型和服务器特定的),但不是Set-Cookie一个。

Windows Phone 8的WebResponse会跳过set-cookie headers吗?

我做了一些更多的测试,set-cookie头只在Windows Phone模拟器上被省略。在实际设备上调试时,报头按预期接收。

它仍然是相当奇怪的我为什么模拟器表现出这种方式。我看到很多关于模拟器中http-only cookie问题的帖子,但没有一个有具体原因。

更新:

在8.0.10322模拟器上的测试工作得很好- cookie被正确处理。看起来默认的手机模拟器对cookie做了一些可疑的事情。