Reputation: 1379
I'm trying to use WebClient.UploadStringAsync method to send some data to server. It works fine when I send POST data, but when using GET, it throws me an error "An exception occurred during a WebClient request."
Here is my code:
WebClient client = new WebClient();
String data = "param1=value1¶m2=value2";
client.UploadStringAsync(new Uri("http://somesite.com"), "GET", data);
Any idea what's going wrong?
Upvotes: 0
Views: 626
Reputation: 1582
Uploading data for a GET breaks convention. You might also want to take a look at HTTPClient which you can install via NuGet.
Upvotes: 0
Reputation: 16826
Don't use UploadStringAsync for GET
. There is DownloadStringAsync designed specifically for that.
Don't use WebClient because it is bound to the UI thread. Use HttpWebRequest instead.
Upvotes: 1