Questions tagged [webrequest]

WebRequest is an abstract class in .NET Framework for making requests to URIs (including HTTP, HTTPS, FTP and FILE protocols). Related tags: [httpwebrequest], [ftpwebrequest].

WebRequest is an abstract class in .NET Framework for making a request to a Uniform Resource Identifier (URI).

MSDN documentation for WebRequest.

1600 questions
36
votes
6 answers

Mocking WebResponse's from a WebRequest

I have finally started messing around with creating some apps that work with RESTful web interfaces, however, I am concerned that I am hammering their servers every time I hit F5 to run a series of tests.. Basically, I need to get a series of web…
Rob Cooper
  • 28,567
  • 26
  • 103
  • 142
35
votes
7 answers

Is WebRequest The Right C# Tool For Interacting With Websites?

I'm writing a small tool in C# which will need to send and receive data to/from a website using POST and json formatting. I've never done anything like this before in C# (or any language really) so I'm struggling to find some useful information to…
Lee
32
votes
2 answers

Creating WPF BitmapImage from MemoryStream png, gif

I am having some trouble creating a BitmapImage from a MemoryStream from png and gif bytes obtained from a web request. The bytes seem to be downloaded fine and the BitmapImage object is created without issue however the image is not actually…
Simon Fox
  • 10,409
  • 7
  • 60
  • 81
30
votes
1 answer

How to Replace WebClient with HttpClient?

I have the following WebClient inside my asp.net mvc web application: using (WebClient wc = new WebClient()) // call the Third Party API to get the account id { string url = currentURL + "resources/" + ResourceID + "/accounts?AUTHTOKEN=" +…
John John
  • 1
  • 72
  • 238
  • 501
29
votes
3 answers

C# - How to make a HTTP call

I wanted to make an HTTP call to a website. I just need to hit the URL and dont want to upload or download any data. What is the easiest and fastest way to do it. I tried below code but its slow and after 2nd repetitive request it just goes into…
Mayur J
  • 371
  • 1
  • 7
  • 14
28
votes
4 answers

HttpWebRequest to URL with dot at the end

when i do a GET with WebRequest.Create("http://abc/test.") i get 404 because according to fiddler the trailing dot gets stripped away by .NET and the web server needs the dot. how can i prevent that or work around it. any workaround is appreciated!
ado
27
votes
3 answers

Using HTTP Authentication with a C# WebRequest

I want to make a web request to a page that needs authenticating. How would I go about doing this? I found something that said possibly to use the Credentials property, but I'm not sure how to use it.
The.Anti.9
  • 43,474
  • 48
  • 123
  • 161
25
votes
4 answers

Multithreading a large number of web requests in c#

I have an program where I need to create some large number of folders to an external sharepoint site (external meaning I can't use the sharepoint object model). Web requests work well for this, but simply doing them one at a time (send request, wait…
Terry
  • 253
  • 1
  • 3
  • 5
22
votes
5 answers

How can I do digest authentication with HttpWebRequest?

Various articles (1, 2) I discovered make this look easy enough: WebRequest request = HttpWebRequest.Create(url); var credentialCache = new CredentialCache(); credentialCache.Add( new Uri(url), // request url "Digest", // authentication type …
Cygon
  • 9,444
  • 8
  • 42
  • 50
21
votes
0 answers

How to properly catch a 404 error in .NET

Possible Duplicate: How can I catch a 404? I would like to know the proper way to catch a 404 error with c# asp.net here is the code I'm using HttpWebRequest request = (HttpWebRequest)…
Luke101
  • 63,072
  • 85
  • 231
  • 359
20
votes
6 answers

What makes this HTTPS WebRequest time out even though it works in the browser?

Here's my request: var request = (HttpWebRequest) WebRequest.Create("https://mtgox.com/"); request.CookieContainer = new CookieContainer(); request.AllowAutoRedirect = false; request.Accept =…
enverpex
  • 1,080
  • 2
  • 8
  • 13
20
votes
5 answers

Starting async method as Thread or as Task

I'm new to C#s await/async and currently playing around a bit. In my scenario I have a simple client-object which has a WebRequest property. The client should send periodically alive-messages over the WebRequests RequestStream. This is the…
KingKerosin
  • 3,639
  • 4
  • 38
  • 77
20
votes
5 answers

How to use WebRequest to POST some data and read response?

Need to have the server make a POST to an API, how do I add POST values to a WebRequest object and how do I send it and get the response (it will be a string) out? I need to POST TWO values, and sometimes more, I see in these examples where it says…
MetaGuru
  • 42,847
  • 67
  • 188
  • 294
20
votes
6 answers

How to calculate HttpWebRequest spent outbound and inbound internet traffic

I have the below function to fetch a page. My question is i want to calculate how much internet connection is spent Both inbound (download) and outbound traffic (sent) How can i do that ? Thank you My function public static string…
Furkan Gözükara
  • 22,964
  • 77
  • 205
  • 342
19
votes
4 answers

"too many automatic redirections were attempted" error message when using a httpWebRequest in .NET

I am attempting to request a page like "http://www.google.com/?q=random" using the webrequest class in vb.net. we are behind a firewall, so we have to authenticate our requests. I have gotten past the authentication part by adding my…
tooleb
  • 612
  • 3
  • 6
  • 14