Questions tagged [httpwebrequest]

HttpWebRequest is a concrete class for .NET Framework applications that provides an HTTP-specific implementation of the abstract WebRequest class. Related tag: [webrequest].

The HttpWebRequest class provides support for the properties and methods defined in WebRequest and for additional properties and methods that enable the user to interact directly with servers using HTTP.

Do not use the HttpWebRequest constructor. Use the WebRequest.Create method to initialize new HttpWebRequest objects. If the scheme for the Uniform Resource Identifier (URI) is http:// or https://, Create returns an HttpWebRequest object.

The GetResponse method makes a synchronous request to the resource specified in the RequestUri property and returns an HttpWebResponse that contains the response. You can make an asynchronous request to the resource using the BeginGetResponse and EndGetResponse methods.

When you want to send data to the resource, the GetRequestStream method returns a Stream object to use to send data. The BeginGetRequestStream and EndGetRequestStream methods provide asynchronous access to the send data stream.

For client authentication with HttpWebRequest, the client certificate must be installed in the My certificate store of the current user.

The HttpWebRequest class throws a WebException when errors occur while accessing a resource. The WebException.Status property contains a WebExceptionStatus value that indicates the source of the error. When WebException.Status is WebExceptionStatus.ProtocolError, the Response property contains the HttpWebResponse received from the resource.

HttpWebRequest exposes common HTTP header values sent to the Internet resource as properties, set by methods, or set by the system; the following table contains a complete list. You can set other headers in the Headers property as name/value pairs. Note that servers and caches may change or add headers during the request.

You can find the documentation for the class on MSDN.

5585 questions
1459
votes
17 answers

Send HTTP POST request in .NET

How can I make an HTTP POST request and send data in the body?
Hooch
  • 28,817
  • 29
  • 102
  • 161
697
votes
51 answers

The request was aborted: Could not create SSL/TLS secure channel

We are unable to connect to an HTTPS server using WebRequest because of this error message: The request was aborted: Could not create SSL/TLS secure channel. We know that the server doesn't have a valid HTTPS certificate with the path used, but to…
Simon Dugré
  • 17,980
  • 11
  • 57
  • 73
441
votes
10 answers

How to send HTTP request in Java?

In Java, How to compose an HTTP request message and send it to an HTTP web server?
Amit
  • 33,847
  • 91
  • 226
  • 299
396
votes
12 answers

Make an HTTP request with android

I have searched everywhere but I couldn't find my answer, is there a way to make a simple HTTP request? I want to request a PHP page / script on one of my websites but I don't want to show the webpage. If possible I even want to do it in the…
Mats Hofman
  • 7,060
  • 6
  • 33
  • 48
376
votes
8 answers

What does %5B and %5D in POST requests stand for?

I'm trying to write a Java class to log in to a certain website. The data sent in the POST request to log in is user%5Blogin%5D=username&user%5Bpassword%5D=123456 I'm curious what the %5B and %5D means in the key user login. How do I decode these…
Rakib Ansary
  • 4,078
  • 2
  • 18
  • 29
341
votes
15 answers

How to post JSON to a server using C#?

Here's the code I'm using: // create a request HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url); request.KeepAlive = false; request.ProtocolVersion = HttpVersion.Version10; request.Method = "POST"; // turn our request string into a…
Arsen Zahray
  • 24,367
  • 48
  • 131
  • 224
331
votes
6 answers

Getting Http Status code number (200, 301, 404, etc.) from HttpWebRequest and HttpWebResponse

I am trying to get the HTTP status code number from the HttpWebResponse object returned from a HttpWebRequest. I was hoping to get the actual numbers (200, 301,302, 404, etc.) rather than the text description. ("Ok", "MovedPermanently", etc.) Is…
James Lawruk
  • 30,112
  • 19
  • 130
  • 137
320
votes
22 answers

Upload files with HTTPWebrequest (multipart/form-data)

Is there any class, library or some piece of code which will help me to upload files with HTTPWebrequest? Edit 2: I do not want to upload to a WebDAV folder or something like that. I want to simulate a browser, so just like you upload your avatar…
dr. evil
  • 26,944
  • 33
  • 131
  • 201
297
votes
13 answers

Pure JavaScript Send POST Data Without a Form

Is there a way to send data using the POST method without a form and without refreshing the page using only pure JavaScript (not jQuery $.post())? Maybe httprequest or something else (just can't find it now)?
John
  • 7,500
  • 16
  • 62
  • 95
229
votes
7 answers

.Net HttpWebRequest.GetResponse() raises exception when http status code 400 (bad request) is returned

I am in a situation where when I get an HTTP 400 code from the server, it is a completely legal way of the server telling me what was wrong with my request (using a message in the HTTP response content) However, the .NET HttpWebRequest raises an…
chefsmart
  • 6,873
  • 9
  • 42
  • 47
226
votes
5 answers

What is the difference between HTTP status code 200 (cache) vs status code 304?

I'm using the Google "Page Speed" plug-in for Firefox to access my web site. Some of the components on my page is indicated as HTTP status: 200 200 (cache) 304 By Google's "Page Speed". What I'm confused about is the difference between 200 (cache)…
Hank
  • 2,301
  • 2
  • 14
  • 6
201
votes
12 answers

Get host domain from URL?

how to get host domain from a string URL? GetDomain has 1 input "URL", 1 Output "Domain" Example1 INPUT: http://support.domain.com/default.aspx?id=12345 OUTPUT: support.domain.com Example2 INPUT: http://www.domain.com/default.aspx?id=12345 OUTPUT:…
001
  • 62,807
  • 94
  • 230
  • 350
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
175
votes
5 answers

How to properly make a http web GET request

I am still new on c# and I'm trying to create an application for this page that will tell me when I get a notification (answered, commented, etc..). But for now I'm just trying to make a simple call to the api which will get the user's data. I'm…
Oscar Reyes
  • 4,223
  • 8
  • 41
  • 75
162
votes
7 answers

Receiving JSON data back from HTTP request

I have a web request that is working properly, but it is just returning the status OK, but I need the object I am asking for it to return. I am not sure how to get the json value I am requesting. I am new to using the object HttpClient, is there a…
user516883
  • 8,868
  • 23
  • 72
  • 114
1
2 3
99 100