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 に答える