如何从Windows Phone 8中的HTTPS网站下载字符串

时间:2015-11-19 07:22:44

标签: c# windows-phone-7 windows-phone-8 https httpwebrequest

我是Windows手机开发者,我想从HTTPS网站下载字符串,我使用

WebClient most_down_download = new WebClient();
most_down_download.DownloadStringCompleted += Most_down_download_DownloadStringCompleted;
most_down_download.DownloadStringAsync(new Uri(https_url));

但它不起作用。你能救我吗?

2 个答案:

答案 0 :(得分:0)

也许是这样的?使用HTTP客户端代替Web客户端(8.1)

HttpClient http = new System.Net.Http.HttpClient();
HttpResponseMessage response = await http.GetAsync(https_url);
webresponse = await response.Content.ReadAsStringAsync();

Reference here

答案 1 :(得分:0)

您需要生成Most_down_download_DownloadStringCompleted事件处理程序,如下所示

void Most_down_download_DownloadStringCompleted(object sender, 
                              System.Net.DownloadStringCompletedEventArgs e)
{
    try
    {
        if (e.Error == null)
        {
            string response = e.Result.ToString();
        }
    }
    catch (Exception ex)
    { }
}

e.Result.ToString()中你从网站上获取字符串