我正在使用WebClient从网页获取页面,当我获得谷歌开始页面一切正常,但当我从vk应用程序接口WebClient返回服务器没有找到页面,但浏览器打开此页面正常我的代码:
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);
}发布于 2012-08-14 20:32:26
这仅适用于具有非200响应状态的https呼叫。如果您收到具有正确凭据的Not found,请检查您的请求参数。
尝试对非200使用此解决方法
client.AllowReadStreamBuffering = true;另外,我看到这一行Uri.EscapeUriString(auth);,我想它一定是auth = Uri.EscapeUriString(auth);
https://stackoverflow.com/questions/11951929
复制相似问题