Windows phone WebClient
-
26-06-2021 - |
Question
I am use WebClient to get page from web, when i get google start page all ok but when i get page from vk api WebClient return Serer not found, but browser open this page normal my code:
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);
}
Solution
This happens only for https
calls with non-200
response status. If you receive Not found
with right credentials, check out your request parameters.
Try this workaround for non-200
:
client.AllowReadStreamBuffering = true;
Also, I see this line Uri.EscapeUriString(auth);
which I think must be auth = Uri.EscapeUriString(auth);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow