从Windows Phone 8上的安全网站检索数据

时间:2014-07-16 15:47:21

标签: c# authentication windows-phone-8 webclient

我正在尝试从授权限制数据库中检索数据,该数据库仅包含我的Windows Phone 8应用程序的文本。我的代码如下所示:

private void Button_Click_1(object sender, RoutedEventArgs e)
{
    WebClient wc = new WebClient();
    wc.DownloadStringCompleted += new DownloadStringCompletedEventHandler(wc_DownloadStringCompleted);
    wc.Credentials = new NetworkCredential("username", "password");
    wc.DownloadStringAsync(new Uri(@"http://www.siteaddress.com"));
}

void wc_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    string text = e.Result;
}

不幸的是我收到以下消息。我做错了吗?提前致谢。 http://s30.postimg.org/yuc0mcb5t/pic.png

1 个答案:

答案 0 :(得分:0)

如果您尝试将数据发送到服务器以接收来自服务器的响应,那么您的意思是将POST数据发送到服务器。

void GetPosts(string UserID)
    {
        WebClient webclient = new WebClient();
        Uri uristring = new Uri("somelink.com");
        webclient.Headers["Content-Type"] = "application/x-www-form-urlencoded";
        string postJsonData = string.Empty;
        postJsonData += "userId=" + UserID;//parameters you want to POST
        webclient.UploadStringAsync(uristring, "POST", postJsonData);
        webclient.UploadStringCompleted += webclient_UploadStringCompleted;
    }

    void webclient_UploadStringCompleted(object sender, UploadStringCompletedEventArgs e)
    {
        .... // any code
    }