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
24
votes
3 answers

How to use String in WebClient.DownloadStringAsync URL

I currently have this for my WebClient URL: WebClient Detail = new WebClient(); Detail.DownloadStringCompleted += new DownloadStringCompletedEventHandler(Detail_DownloadStringCompleted); Detail.DownloadStringAsync(new…
Rhys
  • 2,807
  • 8
  • 46
  • 68
23
votes
4 answers

How to check if a file exists on a server using c# and the WebClient class

In my application I use the WebClient class to download files from a Webserver by simply calling the DownloadFile method. Now I need to check whether a certain file exists prior to downloading it (or in case I just want to make sure that it exists).…
Mats
  • 14,902
  • 33
  • 78
  • 110
23
votes
4 answers

Exception handling the right way for WebClient.DownloadString

I was wondering what exceptions I should protect myself against when using WebClient.DownloadString. Here's how I'm currently using it, but I'm sure you guys can suggest better more robust exception handling. For example, off the top of my head: No…
Only Bolivian Here
  • 35,719
  • 63
  • 161
  • 257
23
votes
2 answers

How can I get the WebClient to use Cookies?

I would like the VB.net WebClient to remember cookies. I have searched and tried numerous overloads classes. I want to login to a website via POST, then POST to another page and get its contents whilst still retaining my session. Is this possible…
Jeremy
  • 3,880
  • 3
  • 35
  • 42
23
votes
2 answers

WebClient - get response body on error status code

I'm looking essentially for the same thing asked here: Any way to access response body using WebClient when the server returns an error? But no answers have been provided so far. The server returns a "400 bad request" status, but with a detailed…
SharpAffair
  • 5,558
  • 13
  • 78
  • 158
23
votes
7 answers

How to check if System.Net.WebClient.DownloadData is downloading a binary file?

I am trying to use WebClient to download a file from web using a WinForms application. However, I really only want to download HTML file. Any other type I will want to ignore. I checked the WebResponse.ContentType, but its value is always null.…
onescaredycat
22
votes
1 answer

Conditional repeat or retry on Mono with webclient from Spring WebFlux

I want implement a conditional repeat on a Mono in WebFlux with WebClient. The situation is the following: We have a rest service service that returns a generated document. The generation of this document is triggered from another service that gets…
Bernado
  • 548
  • 1
  • 6
  • 18
22
votes
5 answers

Get Content-Disposition parameters

How do I get Content-Disposition parameters I returned from WebAPI controller using WebClient? WebApi Controller [Route("api/mycontroller/GetFile/{fileId}")] public HttpResponseMessage GetFile(int fileId) { try { …
The One
  • 4,560
  • 5
  • 36
  • 52
22
votes
6 answers

Use WebClient with socks proxy

Is there any way to use a socks proxy with WebClient? Specifically with the DownloadString method that it provides? I don't want to use any third party stuff like privoxy, freecap whatever and I can't use commercial libraries like those from…
Para
  • 2,022
  • 5
  • 34
  • 73
22
votes
2 answers

Need some advice for trying to mock a .NET WebClient or equivalent

I've got some code which downloads some RSS feeds. I've been using WebClient or Argotic.Syndication.RssFeed libraries. But these aren't mockable :( I definately do not want to hit the real RSS feed every time I run the unit test. Does anyone have…
Pure.Krome
  • 84,693
  • 113
  • 396
  • 647
22
votes
2 answers

How to read a WebClient response after posting data?

Behold the code: using (var client = new WebClient()) { using (var stream = client.OpenWrite("http://localhost/", "POST")) { stream.Write(post, 0, post.Length); } } Now, how do I read the HTTP output?
Jader Dias
  • 88,211
  • 155
  • 421
  • 625
21
votes
8 answers

WebClient 403 Forbidden

I can download this by hand in IE. http://scholar.google.com/scholar.ris?q=info:j8ymU9rzMsEJ:scholar.google.com/&output=citation&hl=zh-CN&as_sdt=2000&oe=GB&ct=citation&cd=0 But, using follow code WebClient client = new…
Begtostudy
  • 1,374
  • 4
  • 13
  • 28
21
votes
2 answers

WebClient - The remote server returned an error: (403) Forbidden

Opening a public page from browser works fine. Downloading same page using WebClient throws - (403) Forbidden. What is going on here ? Here is quick copy/paste example (used on console app) to specific page on web: try { WebClient webClient =…
dzolnjan
  • 1,243
  • 4
  • 14
  • 26
20
votes
2 answers

C# WebClient NTLM authentication starting for each request

Consider a simple C# NET Framework 4.0 application, that: uses WebClient authenticates using NTLM (tested on IIS 6.0 and IIS 7.5 server) retrieves a string from an URL multiple times using DownloadString() Here's a sample that works fine: using…
c4n
  • 639
  • 1
  • 5
  • 11
20
votes
2 answers

Client Web Browser Behavior When Handling 301 Redirect

The RFC seems to suggest that the client should permanently cache the response: http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html 10.3.2 301 Moved Permanently The requested resource has been assigned a new permanent URI and any future…