windows phone 8在httpclient中使用webbrowser cookie

时间:2014-02-16 11:32:35

标签: c# windows-phone-8 dotnet-httpclient

我正在尝试从Windows Phone 8中的Webbrowser元素中获取Cookie,然后使用该Cookie将httpclient连接到steamgifts.c​​om。

previewbro.IsScriptEnabled = true;
previewbro.IsEnabled = true;
previewbro.Navigate(new Uri("https://steamcommunity.com/openid/login?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0&openid.mode=checkid_setup&openid.return_to=http%3A%2F%2Fsteamgifts.com%2F%3Flogin&openid.realm=http%3A%2F%2Fsteamgifts.com&openid.ns.sreg=http%3A%2F%2Fopenid.net%2Fextensions%2Fsreg%2F1.1&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select"));

我使用它通过浏览器登录Steam并获取Cookie。然后我尝试将Cookie提供给httphandler:

        Uri adress = new Uri("http://www.steamgifts.com/");
        String html;
        HttpClientHandler handle = new HttpClientHandler();
        CookieCollection cookies;
        try
        {
            cookies = previewbro.GetCookies();
        }
        catch (Exception fehler1)
        {
            label.Text = fehler1.ToString();
            cookies = null;
        }
        try
        {
            if (cookies != null)
            {
                handle.CookieContainer.Add(adress, cookies);
                label.Text = "got cookies";
            }
        }
        catch (Exception fehler2)
        {
            label.Text = fehler2.ToString();

        }
        HttpClient client = new HttpClient(handle);

        var responsetask = client.GetAsync(adress);
        HttpResponseMessage response = await responsetask;
        html = await response.Content.ReadAsStringAsync();
        previewbro.NavigateToString(html);

我得到的回应显示我还没有进入。 我错过/做错什么提示? 或者我错过了解它应该如何运作?

0 个答案:

没有答案