Windows Phone 8.1 CookieContainer和XMLConnect cookie问题

时间:2016-05-22 15:44:38

标签: c# magento cookies windows-phone-8.1 winrt-xaml

我正在开发一个与Magento XMLConnect API通信的Windows Phone 8.1购物应用程序。我的问题是服务器发送的cookie存储在我的CookieContainer中,但是当我向服务器发送请求时,不会发送cookie。如果我通过明确设置域和键值对手动将cookie重新添加到CookieContainer,则会发送cookie并且一切正常。这个解决方案可以为app init手动添加appcode cookie和screenize cookie,但当然我不能用前端cookie(识别用户)来做到这一点,因为那不是常数。因此结果是我的请求总是丢失前端cookie,因此服务器无法识别用户,即用户未登录。 有什么想法解决方案?使用XMLConnect时,它是CookieContainer的已知行为吗?

 public static CookieContainer cookies = new CookieContainer();
    public static HttpClientHandler handler = new HttpClientHandler();
    private static System.Net.Http.HttpClient client;

 public static async Task<string> httpGET(string url)
    {

        string resp = "";
        byte[] response = new byte[] { };

        if (cookies.Count == 0)
        {
            cookies.Add(new Uri(url...), new Cookie("app_code", "defand1"));
            cookies.Add(new Uri(url...), new Cookie("screen_size", "2560x2560"));    
        }
        try
        {
            response = await client.GetByteArrayAsync(url);
            resp = Encoding.UTF8.GetString(response, 0, response.Length);
            string httpResponse = resp;
        }
        catch (Exception)
        {
            throw;
        }
        return resp;
    }

     public static async Task<string> httpPOST(string url)
    {
        System.Net.Http.HttpResponseMessage repi = client.GetAsync(baseURL).Result;
        string resp = "";

        System.Net.Http.HttpResponseMessage response = new System.Net.Http.HttpResponseMessage();
        response.EnsureSuccessStatusCode();
        Task<string> getStringAsync = response.Content.ReadAsStringAsync();
        resp = await getStringAsync;
        return resp;
    }

0 个答案:

没有答案