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

WebRequest bug?

EDIT: Solved, the problem was server-side. I'm using C# and .NET2 and I wonder is that a WebRequest bug.. I do several good requests with this method and all is fine, but after that every time I get "The operation has timed out.". I really don't…
blez
  • 4,939
  • 5
  • 50
  • 82
2
votes
2 answers

How do I seamlessly compress the data I post to a form using C# and IIS?

I have to interface with a slightly archaic system that doesn't use webservices. In order to send data to this system, I need to post an XML document into a form on the other system's website. This XML document can get very large so I would like to…
flytzen
  • 7,348
  • 5
  • 38
  • 54
2
votes
1 answer

Get the .ASPXAUTH cookie value programmatically II

I am attempting to retrieve the ASPXAUTH cookie programmatically without success. A similar question posted to this forum did not prove helpful. My code is shown below. One known gotcha is to be sure to assign a CookieContainer to the request,…
Brett
  • 8,575
  • 5
  • 38
  • 51
2
votes
0 answers

simulate http request connection close Vertx HttpServerRequest

It seems a stupid case but I want to simulate http request connection close, and for now I could not find the way to do it. In my server mock I implement this code private JsonObject setStatus(HttpServerRequest req, JsonObject content) { int…
paul
  • 12,873
  • 23
  • 91
  • 153
2
votes
2 answers

HttpWebRequest Won't Serialize

I'm getting the following error when I try to Serialize an HttpWebRequest Type 'System.Net.KnownHttpVerb' in Assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' is not marked as serializable. Using .Net…
dr. evil
  • 26,944
  • 33
  • 131
  • 201
2
votes
3 answers

Intermittent exception: java.net.UnknownHostException: profile.ak.fbcdn.net

I try to retrieve a picture from e.g http://graph.facebook.com/btaylor/picture using the following code: DefaultHttpClient httpClient = new DefaultHttpClient(); HttpGet request = new HttpGet(urlString); HttpResponse response =…
Gilbert
  • 901
  • 1
  • 10
  • 22
2
votes
2 answers

Secure online-game http get/post request (How to avoid repeated sending of the same http-req)

In my game/app (iPhone) the client side sends http requests (get or post) to the game http server. Requests have this form: gameserver.com/userId/givebonus/100 This for example would give the userId a bonus of 100. Now, we encrypt the server request…
Dado
  • 1,147
  • 1
  • 13
  • 31
2
votes
1 answer

vexed! POST returns a 302 found object moved error in HttpWebRequest

Someone please help - been struggling with this lousy problem! What I'm doing - I have an ASPX page from which I originate a GET and then a POST to a HTTPS page with a view to login to it. I have spent quite a bit of time comparing my GET and POST…
Gerry
  • 866
  • 2
  • 12
  • 31
2
votes
0 answers

HttpWebRequest with proxy exception

I have a next problem: when I try to create a HttpWebRequest with proxy, I get a WebException with the message The underlying connection was closed: The connection was closed unexpectedly. What I am doing wrong? Here is my code: var…
2
votes
1 answer

Can't get content of website with c#

This is my lines of code for get content of website: private string GetContent(string url) { var request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; var content = String.Empty; HttpStatusCode statusCode; …
Hau Le
  • 667
  • 2
  • 17
  • 42
2
votes
1 answer

receiving X509 client certificates in web requests

I am trying to send an X509Certificate from an Http Handler to a web service that will receive and read the certificate to authenticate the user. I know the certificate is sending fine; I have a tester that lets me look at the HttpWebRequest before…
YYY
  • 21
  • 4
2
votes
0 answers

login to aspx page from another site using httprequest

Using C# and ASP.NET I want to programmatically fill login detail on a web page (form) and then 'POST' those values. How do I do this?currently i am using below code but it not work it take me on same page. HttpWebRequest req =…
2
votes
0 answers

HttpWebResponse body is unreadable

I created a c# application that would integrate with Picarto.tv. The problem is during the login stage, where the program has to send a WebRequest to the picarto login server with login details and receive the response. I was successful sending the…
Ghosti
  • 23
  • 5
2
votes
1 answer

Avoid HttpWebRequest GET and ProtocolViolationException

Is there anyway to prevent HttpWebRequest.GetRequestStream from throwing an exception when the method is GET? I know that HEAD and GET should not contain a body in valid HTTP, but some servers accept bodies for these methods anyway (e.g.,…
Travis Parks
  • 8,435
  • 12
  • 52
  • 85
2
votes
1 answer

How to process custom certificates in HTTPS?

I am trying to fetch a page using HttpWebRequest, but I am getting this exception: Could not establish trust relationship for the SSL/TLS secure channel. Is it possible to specify a custom RemoteCertificateValidationCallback for a particular…
TN.
  • 18,874
  • 30
  • 99
  • 157