Questions tagged [webclient]

WebClient is a class for .NET Framework applications that provides methods for sending and receiving data from a resource identified by a URI.

Read more about the WebClient class and its usage here: https://learn.microsoft.com/en-us/dotnet/api/system.net.webclient

4098 questions
349
votes
9 answers

How to post data to specific URL using WebClient in C#

I need to use "HTTP Post" with WebClient to post some data to a specific URL I have. Now, I know this can be accomplished with WebRequest but for some reasons I want to use WebClient instead. Is that possible? If so, can someone show me some example…
Desolator
  • 22,411
  • 20
  • 73
  • 96
271
votes
6 answers

Deciding between HttpClient and WebClient

Our web application is running in .NET Framework 4.0. The UI calls the controller methods through Ajax calls. We need to consume the REST service from our vendor. I am evaluating the best way to call the REST service in .NET 4.0. The REST service…
user3092913
  • 2,735
  • 2
  • 12
  • 4
257
votes
12 answers

How to change the timeout on a .NET WebClient object

I am trying to download a client's data to my local machine (programatically) and their webserver is very, very slow which is causing a timeout in my WebClient object. Here is my code: WebClient webClient = new WebClient(); webClient.Encoding =…
Ryall
  • 12,010
  • 11
  • 53
  • 77
222
votes
11 answers

HTTP POST Returns Error: 417 "Expectation Failed."

When I try to POST to a URL it results in the following exception: The remote server returned an error: (417) Expectation Failed. Here's a sample code: var client = new WebClient(); var postData = new…
Saeb Amini
  • 23,054
  • 9
  • 78
  • 76
185
votes
3 answers

What difference is there between WebClient and HTTPWebRequest classes in .NET?

What difference is there between the WebClient and the HttpWebRequest classes in .NET? They both do very similar things. In fact, why weren't they merged into one class (too many methods/variables etc may be one reason but there are other classes in…
GurdeepS
  • 65,107
  • 109
  • 251
  • 387
163
votes
3 answers

How to get a JSON string from URL?

I'm switching my code form XML to JSON. But I can't find how to get a JSON string from a given URL. The URL is something like this: "https://api.facebook.com/method/fql.query?query=.....&format=json" I used XDocuments before, there I could use the…
ThdK
  • 9,916
  • 23
  • 74
  • 101
158
votes
5 answers

Using CookieContainer with WebClient class

I've previously used a CookieContainer with HttpWebRequest and HttpWebResponse sessions, but now, I want to use it with a WebClient. As far as I understand, there is no built-in method like there is for HttpWebRequests (request.CookieContainer). How…
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173
137
votes
8 answers

WebClient vs. HttpWebRequest/HttpWebResponse

It seems to me that most of what can be accomplished with HttpWebRequest/Response can also be accomplished with the WebClient class. I read somewhere that WebClient is a high-level wrapper for WebRequest/Response. So far, I can't see anything that…
Dan
  • 11,077
  • 20
  • 84
  • 119
111
votes
14 answers

DataBufferLimitException: Exceeded limit on max bytes to buffer webflux error

While sending a file I receive an array of bytes. I always have a problem with webflux to receive an array. the error thrown as below : org.springframework.core.io.buffer.DataBufferLimitException: Exceeded limit on max bytes to buffer : 262144 …
taveced
  • 1,133
  • 2
  • 7
  • 6
102
votes
3 answers

POSTing JSON to URL via WebClient in C#

I have some JavaScript code that I need to convert to C#. My JavaScript code POSTs some JSON to a web service that's been created. This JavaScript code works fine and looks like the following: var vm = { k: "1", a: "2", c: "3", v: "4" }; $.ajax({ …
Eels Fan
  • 2,043
  • 6
  • 22
  • 23
98
votes
10 answers

How to get status code from webclient?

I am using the WebClient class to post some data to a web form. I would like to get the response status code of the form submission. So far I've found out how to get the status code if there is a exception Catch wex As WebException If TypeOf…
julio
  • 1,069
  • 1
  • 7
  • 8
94
votes
1 answer

WebClient.DownloadString results in mangled characters due to encoding issues, but the browser is OK

The following code: var text = (new WebClient()).DownloadString("http://export.arxiv.org/api/query?search_query=au:Freidel_L*&start=0&max_results=20")); results in a variable text that contains, among many other things, the string "$κ$-Minkowski…
Domenic
  • 110,262
  • 41
  • 219
  • 271
93
votes
4 answers

Set timeout for webClient.DownloadFile()

I'm using webClient.DownloadFile() to download a file can I set a timeout for this so that it won't take so long if it can't access the file?
UnkwnTech
  • 88,102
  • 65
  • 184
  • 229
90
votes
5 answers

How can I programmatically remove the 2 connection limit in WebClient

Those "fine" RFCs mandate from every RFC-client that they beware of not using more than 2 connections per host... Microsoft implemented this in WebClient. I know that it can be turned off with App.config:
Christian
  • 2,903
  • 4
  • 31
  • 34
88
votes
9 answers

Download file with WebClient or HttpClient?

I am trying to download file from a URL and I have to choose between WebClient and HttpClient. I have referenced this article and several other articles on the internet. Everywhere, it is suggested to go for HttpClient due to its great async support…
Saket Kumar
  • 4,363
  • 4
  • 32
  • 55
1
2 3
99 100