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

WebResponse contentLength property is -1?

I have a windows application that gets URL and download .jpeg file. For some urls the ContentLength property is -1, therefore it throws exception. Here is my code: var url = new Uri(sUrlToReadFileFrom[i]); _request =…
2
votes
1 answer

XDocument.Load(feedUrl) returns "Data at the root level is invalid. Line 1, position 1."

first of all, this is more of a solution, than a question. It took me a while to resolve, so I thought my resolution might worth sharing. I was trying to load an RSS feed using XDoument.Load(feedUrl) and was getting the above Exception. I checked…
Adam Hey
  • 1,512
  • 1
  • 20
  • 24
2
votes
2 answers

XmlDocument.Load: Could not create SSL/TLS secure channel

I have simple code similar to this strewn through my application: new XmlDocument().Load("https://mybookingpal.com/xml/rest/product/organization/5?pos=" + "a3a2e74b809e0e87"); The above is the new domain, the old domain is: new…
Sean
  • 14,359
  • 13
  • 74
  • 124
2
votes
1 answer

Writing file from HttpWebRequest periodically vs. after download finishes?

Right now I am using this code to download files (with a Range header). Most of the files are large, and it is running 99% of CPU currently as the file downloads. Is there any way that the file can be written periodically so that it does not remain…
WB3000
  • 77
  • 2
  • 6
2
votes
0 answers

Uploading a file using an API

I want to upload a file (continuously, not chunked) using the site's API. Here are the information of the API: Request to: http://server/upv3.php Required Vars: [username] account username [password] account…
Feve123
  • 122
  • 11
2
votes
1 answer

How to send a HttpWebRequest with proxy address from Windows phone application

I am developing a Windows phone mobile application. I need to send a WebRequest for a specific URL. See below HttpWebRequest request = (HttpWebRequest)System.Net.WebRequest.Create(@"http://www.test.html"); using (HttpWebResponse response =…
Anees Deen
  • 1,385
  • 2
  • 17
  • 31
2
votes
1 answer

Accessing the buffered request body in HttpWebRequest?

By default HttpWebRequest has AllowWriteStreamBuffering set to true, which means that all data written to the request stream is buffered inside the object. I'd like to access this buffer of data after it has been written, but can't seem to find any…
Greg Beech
  • 133,383
  • 43
  • 204
  • 250
2
votes
2 answers

C# Console Application httpWebRequest

Im trying to create a very simple c# console application to post some data to a web api. However whatever I do I get an error on the response like: responseText "{\"info\":{\"status\":\"failed\",\"error\":{\"code\":1000,\"message\":\"Invalid …
user1517598
  • 111
  • 1
  • 4
  • 11
2
votes
0 answers

Why is WebRequest timeout not honored for SSL over a proxy?

If I run the following code, which tries to GET a HTTPS URL on an endpoint that is not answering (notice the port); then it throws a timeout WebException when a second has passed, as I would expect: var request =…
driis
  • 161,458
  • 45
  • 265
  • 341
2
votes
1 answer

KeepAliveException when using HttpWebRequest.GetResponse

I am trying to POST an attachment to CouchDB using the HttpWebRequest. However, when I attempt "response = (HttpWebResponse)httpWebRequest.GetResponse();" I receive a WebException with the message "The underlying connection was closed: A connection…
Lucas
  • 478
  • 4
  • 15
2
votes
1 answer

what .NET class to proxy HTTP requests through? (and keep track of bandwidth used)

What .NET class/methods could I use to write a simple HTTP(s) proxy that would run on my PC that would: Proxy all HTTP(S) requests through it Let me get bandwidth used per proxy'ed request (e.g. content length) Let me get requesting application or…
Greg
  • 34,042
  • 79
  • 253
  • 454
2
votes
1 answer

GAE HTTP method support

I get an "unrecognized HTTP method" when trying to do a REPORT request using httplib and gae. Is there a workaround available? An httplib patch for gae? Do you I have to find another host in order to do this natively? According to the docs, only…
user306082
  • 21
  • 1
2
votes
5 answers

WebRequest.Create problem

My requirement is downlaoding a HTTM page. Like and I am using WebRequest.Create. But the line HttpWebRequest request = (HttpWebRequest) WebRequest.Create("http://www.mayosoftware.com"); Is throwing an exception {"Configuration system failed to…
CrazyC
  • 1,840
  • 6
  • 39
  • 60
2
votes
1 answer

DefaultHttpClient GET and POST commands Java Android

Ok this is my application : An Android app to allow me to submit CokeZone codes into CokeZone.co.uk from a mobile app instead of from the website. So I wrote this section of code to do the post logon command and then check to see if im logged in…
RenegadeAndy
  • 5,440
  • 18
  • 70
  • 130
2
votes
0 answers

HttpWebrequest/WebClient/HttpClient/CookieContainer bug? Does not add cookie if Response Uri does not contain it's path

I was trying to log in to my WordPress admin panel using C# (WebClient/HttpWebRequest). I send a POST request to /wp-login.php. It responds with cookies like this: Set-Cookie: wordpress_26...cf9e; path=/wordpress/wp-content/plugins;…
Alex P.
  • 3,697
  • 9
  • 45
  • 110