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
1 answer

Differences between a HttpURLConnection and a browser connection

I'm trying to connect to a web page through a HttpURLConnection but it's not responding the same as a regular browser (firefox, chrome). I'm getting an error 500. With the same code I can get "anyother" page (google, for example). My code is posted…
user470610
  • 21
  • 1
  • 2
2
votes
2 answers

HttpWebRequest WebProxy problem - The connection was closed unexpectedly

I'm trying to make a HTTP request through an open SOCKS5 proxy. I have verified that the proxy works by setting it as a proxy for Firefox before setting it as the proxy in my C#.Net application by setting request.Proxy = new WebProxy(ip,…
JoeR
  • 1,901
  • 3
  • 25
  • 39
2
votes
2 answers

C# - Is there a limit to the size of an httpWebRequest stream?

I am trying to build an application that downloads a small binary file (20-25 KB) from a custom webserver using httpwebrequests. This is the server-side code: Stream UpdateRequest = context.Request.InputStream; byte[] UpdateContent = new…
Annonymus
  • 204
  • 1
  • 2
  • 10
2
votes
0 answers

System.ComponentModel.Win32Exception: The client and server cannot communicate, because t hey do not possess a common algorithm

I was trying to read the data returned from a url. Consider the following code: private static void Read() { _targetUrl = "https://url"; _proxyUrl = "http://differentUrl:8080"; ServicePointManager.ServerCertificateValidationCallback +=…
Khairul
  • 191
  • 2
  • 14
2
votes
1 answer

How can I check if I have image loaded using dataWithContentsOfURL in iPhone?

In my iPhone app I'm loading images using this line of code: UIImage *image = [UIImage imageWithData: [NSData dataWithContentsOfURL:url]]; How can I check if I have image loaded? I mean sometimes it doesn't give any error, but I have blank white…
Burjua
  • 12,506
  • 27
  • 80
  • 111
2
votes
2 answers

http request from Google App Engine

I'm trying to make http requests from my Google App Engine webapp, and discovered I have to use URLConnection since it's the only whitelisted class. The corresponding Clojure library is clojure.contrib.http.agent, and my code is as…
yayitswei
  • 4,587
  • 5
  • 27
  • 34
2
votes
2 answers

How to know redirect URL

Possible Duplicate: A way to figure out redirection URL C# Issue: If we type the following url (see warning) http://migre.me/13rQa It will redirect to oooooo1.ru I like to know the redirected URL from C#. Anybody knows how to do it. P.S: These…
CrazyC
  • 1,840
  • 6
  • 39
  • 60
2
votes
2 answers

How to download only the headers with WebRequest

I’m writing some scripts to look for vulnerabilities to the padding oracle exploit in ASP.NET for which I need to look at the HttpStatusCode in the response. I’m doing this across a large number of my sites with different scenarios and performance…
Troy Hunt
  • 20,345
  • 13
  • 96
  • 151
2
votes
1 answer

System.Net.WebException: Unable to connect to the remote server error while just making post with HttpWebRequest?

I have HttpWebRequest and its giving this error.I cannot try this answer because i cannot use local ip.There is a strange issue that in my computer there is no error like this but in the server its giving this error.The database is not in server we…
mr.
  • 679
  • 12
  • 30
2
votes
0 answers

HttpWebRequest automatically encodes URI

So I've got a site in .NET 2.0 (VB.NET) I need to send a request to a third party service with a WebRequest. Unfortunately, the request needs to send URL encoded data in the query string and it appears that the HTTP request object automatically…
Chuck Finley
  • 295
  • 1
  • 4
  • 12
2
votes
1 answer

server doesn't read request without mime-type

I'm having issue reading the contents of the request body at the server end. Apparently the server only reads files which have a content type. Like if the client sends the request with the header : "Content-Disposition: form-data;…
Ahmed Mujtaba
  • 2,110
  • 5
  • 36
  • 67
2
votes
0 answers

C# Slow Webrequest in windows server 2008 R2

I use this code on a PC and all my webrequest take less than a second but When I run it on my vps with windows server 2008 R2 it extremely slow(took about 40 seconds for one request) var restClient=new RestClient(new Uri("my web service…
2
votes
1 answer

Htmlagilitypack after login to Https Website with HttpWebRequest?

I want to parse some html site like pluralsight,Forexample (https://app.pluralsight.com/id?), So How can I first login site programmaticaly (without using webbrowser control) then call another url (for example : Pluralsight) and get response and…
Matteo
  • 21
  • 2
2
votes
1 answer

send POST request to custom URI in default browser

I need to open system default browser and send to some custom URI POST data. So I have two part of code: first - opens def browser and another must send POST data to it, but does not do it. What can you say about it? enter code here private void…
yozhik
  • 4,644
  • 14
  • 65
  • 98
2
votes
0 answers

Why HttpWebResponse response was cached and setting the DefaultCachePolicy for HttpWebRequest did not work?

I have a web role in which I have the following code snippet: var webRequest = HttpWebRequest.Create(path); webRequest.Timeout = 5000; webRequest.Method = "GET"; It's requesting a resource from Azure CDN, so path is something like the…
gdyrrahitis
  • 5,598
  • 3
  • 23
  • 37