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

Dailymotion JS API - No 'Access-Control-Allow-Origin' header is present on the requested resource

I'm currently trying to retrieve videos from a private Dailymotion channel in my personal application. To do that I'm trying to authenticate to the Dailymotion API using the grant_type method : password. Here is my POST request : xhr.open('POST',…
2
votes
1 answer

422 error returned in HttpWebRequest post

I'm getting a "The remote server returned an error: (422) Unprocessable Entity." when trying to do a post to login to a site. The code I'm using look something like below. var cookieContainer = new CookieContainer(); string postData =…
Riri
  • 11,501
  • 14
  • 63
  • 88
2
votes
1 answer

C#.NET - Signing HTTP POST message with HMAC-SHA512 produces inconsistent result in some systems

I'm building a program that interacts with a cryptocurrency exchange's API to place buy/sell order, etc. In order to use the exchange's private API methods, I have to include a sign in the http header, which is the POST message body, encrypted with…
2
votes
2 answers

NET: Check URL's response status code without using IP Address

I want to check the status code for a web url without using the IP address as I have many websites configured with the same IP and only hostname is different for them. The HttpWebRequest resolves the IP Address and use it. Is there an alternative?
2
votes
1 answer

Encoding problem with reading website, three different encodings

I have a problem with a WebRequest in C#. It's a google page. The header states text/html; charset=ISO-8859-1 The website states And finally I only get the expected Result in the…
Scoox
  • 181
  • 2
  • 11
2
votes
1 answer

Exception when downloading data from HTTPS site

I am working on a siteripper / screenscraper for looking up tracking information on the Royal Mail website. Unfortunately Royal Mail do not support an API, so this is the way to do it. I keep getting the same exception no matter what I do. (The…
chjortlund
  • 3,613
  • 2
  • 31
  • 30
2
votes
2 answers

(ASP.NET) Stream.Write fails on server but works on dev machine - any ideas?

I was wondering whether anyone had encountered a problem with Stream.Write() where it works under a dev (Windows 7) environment but fails under a server environment (Windows 2008 R2 Enterprise)? I'm basically working with some third party code which…
jtc
  • 21
  • 1
2
votes
3 answers

Security advice: SSL and API access

My API (a desktop application) communicates with my web app using basic HTTP authentication over SSL (Basically I'm just using https instead of http in the requests). My API has implemented logic that makes sure that users don't send incorrect…
David
  • 7,310
  • 6
  • 41
  • 63
2
votes
2 answers

Why would C# HttpWebRequest return 500 error on ResponseStream, but not with PHP?

I would be very grateful if anyone could help me out with this problem. I've got some C# code which reads in the contents of a web page for parsing later on. The code is: private StringReader ReadInUrl(string url) { …
Beon
  • 25
  • 1
  • 3
2
votes
1 answer

How do I resolve a JSON response of special characters?

How do I resolve a JSON response of special characters? When I use the Postman tool with this URL, I receive valid and expected JSON. However, when I make a HTTP request with this url within .Net, I receive a response of special characters. The code…
Scott Nimrod
  • 11,206
  • 11
  • 54
  • 118
2
votes
3 answers

Why is the Request.Form.AllKeys collection empty after a POST and Redirect?

I have an aspx page where I want to post values to a new page and then redirect to that new page. I don't get any errors and the redirection occurs but the AllKeys collection is always empty. Here's an example of my code: Try With strPost …
Chris
  • 21
  • 1
  • 2
2
votes
0 answers

Rest Client Authorization error

I want to call a rest client with basic authorization. I tried this but got a Unauthorized(401) exception in c# : HttpWebRequest client = (HttpWebRequest)WebRequest.Create("http://someurl.com"); client.Method = "POST"; …
fakhrad
  • 21
  • 2
2
votes
1 answer

Getting QueryStrings from WebRequest

Lets say i have this: WebRequest myWebRequest1 = (WebRequest)asynchronousResult.AsyncState; i know that i can get the url like this myWebRequest1.RequestUri but i was wondering if there is any way to get the query strings using a better way than…
Stacker
  • 8,157
  • 18
  • 73
  • 135
2
votes
1 answer

How to send image with http.post

I would like to send image with http.post. I use that code block , but gives me 404 error. I tried api on postman , return success. Where is my wrong? Thanks. changeprofileimg() { this.camera.getPicture({ sourceType:…
Ahmet emre CETIN
  • 321
  • 1
  • 4
  • 22
2
votes
1 answer

HttpWebRequest POST adds a NULL value to Form Variables

I am attempting to call a RESTful service using an HttpWebRequest object via POST. I am attempting to pass 1 variable with the Request body which contains a url encoded string. I see the request when it hits the server; however, it shows 2 form…
JamesEggers
  • 12,885
  • 14
  • 59
  • 86