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
176
votes
11 answers

HttpWebRequest using Basic authentication

I'm trying to go through an authentication request that mimics the "basic auth request" we're used to seeing when setting up IIS for this behavior. The URL is:…
Kenny Rullo
  • 2,467
  • 2
  • 16
  • 7
138
votes
13 answers

Cannot set some HTTP headers when using System.Net.WebRequest

When I try to add a HTTP header key/value pair on a WebRequest object, I get the following exception: This header must be modified using the appropriate property I've tried adding new values to the Headers collection by using the Add() method but…
Razor
  • 17,271
  • 25
  • 91
  • 138
124
votes
4 answers

How do I use WebRequest to access an SSL encrypted site using HTTPS?

I'm writing a program that reads content from a user provided URL. My problem is in the code that goes something like this: Uri uri = new Uri(url); WebRequest webRequest = WebRequest.Create(uri); WebResponse webResponse =…
Alfred B. Thordarson
  • 4,460
  • 8
  • 39
  • 37
109
votes
4 answers

Cannot send a content-body with this verb-type

I just got this exception (ProtocolViolationException) in my .NET 2.0 app (running on windows mobile 6 standard emulator). What confuses me is that as far as i know, I have not added any content body, unless I've inadvertently done it somehow. My…
Brian Sweeney
  • 6,693
  • 14
  • 54
  • 69
88
votes
2 answers

How to get json response using system.net.webrequest in c#?

I need to get json data from an external domain. I used WebRequest to get the response from a website. Here's the code: var request = WebRequest.Create(url); string text; var response = (HttpWebResponse) request.GetResponse(); using (var sr = new…
h3n
  • 5,142
  • 9
  • 46
  • 76
82
votes
3 answers

Which versions of SSL/TLS does System.Net.WebRequest support?

Now that SSL 3 has been found to be vulnerable to the POODLE attack: Which versions of SSL/TLS does System.Net.WebRequest use when connecting to any https Uri? I use WebRequest to connect to several 3rd party API's. One of these has now said they…
JK.
  • 21,477
  • 35
  • 135
  • 214
82
votes
2 answers

How do you send an HTTP Get Web Request in Python?

I am having trouble sending data to a website and getting a response in Python. I have seen similar questions, but none of them seem to accomplish what I am aiming for. This is my C# code I'm trying to port to Python: static void Request(Uri…
voice
  • 1,326
  • 1
  • 11
  • 16
72
votes
10 answers

Mono https webrequest fails with "The authentication or decryption has failed"

I'm making a simple REST client to use in my C# applications. In .net on Windows It works great with http:// and https:// connections. In mono 2.6.7 (Also tested with 2.8 with the same results) on Ubuntu 10.10 only http:// works. https://…
Joel
  • 16,474
  • 17
  • 72
  • 93
55
votes
4 answers

Forcing Basic Authentication in WebRequest

I am integrating web service that will use an HTTP-POST to request and retrieve data. The remote server requires basic authentication as per RFC 2617 My attempts to authenticate are failing. It fails in that, even though I attach a…
Himanshu
  • 653
  • 1
  • 5
  • 7
54
votes
7 answers

Test if a website is alive from a C# application

I am looking for the best way to test if a website is alive from a C# application. Background My application consists of a Winforms UI, a backend WCF service and a website to publish content to the UI and other consumers. To prevent the situation…
FryHard
  • 10,305
  • 7
  • 35
  • 38
53
votes
1 answer

HttpWebRequest: Add Cookie to CookieContainer -> ArgumentException (Parametername: cookie.Domain)

I'm trying to login to a website via my application. What I did: First I figured out how the browser does the authorization process with Fiddler. I examined how the POST request is built and I tried to reconstruct it. The browser sends 4 cookies…
TorbenJ
  • 4,462
  • 11
  • 47
  • 84
49
votes
4 answers

Making a web request to a web page which requires windows authentication

I am trying to make a request to a web page using WebRequest class in .net. The url that I am trying to read requires Windows Authentication due to which I get an unauthorised exception. How can I pass a windows credentials to this request so that…
Hemanshu Bhojak
  • 16,972
  • 16
  • 49
  • 64
48
votes
10 answers

Reasons for a 409/Conflict HTTP error when uploading a file to sharepoint using a .NET WebRequest?

I've got a method that uses a WebRequest to upload a file to a sharepoint 2010 list/folder, using a PUT request, with the Overwrite Header set to T (overwrite). When several files are uploaded (method is called several times), some requests fail…
GR7
  • 5,083
  • 8
  • 48
  • 66
47
votes
10 answers

HttpWebRequest times out on second call

Why does the following code Timeout the second (and subsequent) time it is run? The code hangs at: using (Stream objStream = request.GetResponse().GetResponseStream()) and then causes a WebException saying that the request has timed out. I have…
Darbio
  • 11,286
  • 12
  • 60
  • 100
37
votes
4 answers

How to force WebRequest to send Authorization header during POST

When using WebRequest to send a POST, the Authorization header is not sent with the request even though I have manually set the header and set PreAuthenticate to true, eg: webRequest.Headers["Authorization"] = "OAuth…
chris
  • 1,731
  • 4
  • 26
  • 33
1
2 3
99 100