1

我正在使用 WebClient 从 web 获取页面,当我得到 google 起始页面时一切正常,但是当我从 vk api WebClient 获取页面时返回 Serer 未找到,但浏览器正常打开此页面我的代码:

private void log_Click(object sender, RoutedEventArgs e)
{
    string auth;
    string login = Uri.EscapeUriString(this.login.Text);
    string password = Uri.EscapeUriString(this.pass.Password);
    auth = "https://api.vk.com/oauth/token";
    auth += "?grant_type=password" + "&client_id=id&client_secret=code&username=" + login + "&password=" + password + "&scope=notify,friends,messages";

    //auth = "https://google.com/";

    WebClient client = new WebClient();
    client.DownloadStringCompleted +=new DownloadStringCompletedEventHandler(client_DownloadStringCompleted);
    Uri.EscapeUriString(auth);
    client.DownloadStringAsync(new Uri(auth));
}
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
    if (e.Error == null)
         MessageBox.Show("Using WebClient: " + e.Result);

    else
        MessageBox.Show(e.Error.Message);
}
4

1 回答 1

2

这只发生https在无200响应状态的呼叫中。如果您收到Not found正确的凭据,请检查您的请求参数。

尝试此解决方法用于非200

client.AllowReadStreamBuffering = true;

另外,我看到这条线Uri.EscapeUriString(auth);我认为必须是auth = Uri.EscapeUriString(auth);

于 2012-08-14T12:32:26.173 回答