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

Cookie not being returned on response via HttpWebRequest

Scope: I have been trying to simulate the request for this brazilian site and even though it "works" (I can read the correct HTML from the response), I get no "Cookies" back, when there should be at least one. Tooling: I am using Fiddler2 and…
Marcello Grechi Lins
  • 3,350
  • 8
  • 38
  • 72
2
votes
1 answer

About choose buffer size in HttpWebRequest GetResponseStream

var h = (HttpWebRequest)WebRequest.Create(url); using (var hr = (HttpWebResponse)(await h.GetResponseAsync())) { using (var s = hr.GetResponseStream()) { using (var f = new FileStream(saveTo, FileMode.Create, FileAccess.Write,…
NoName
  • 7,940
  • 13
  • 56
  • 108
2
votes
1 answer

How to call a web service using HttpWebRequest

I am able to successfully retrieve the wsdl from a server with the code below. How can I now call a method (GetVersion) from this same service? Trying http://www.servername.com/DataService.asmx/GetVersion returns an error saying the page cannot be…
Bill
  • 3,806
  • 5
  • 33
  • 45
2
votes
2 answers

«HTTP::Message content must be bytes» error when trying to post

I have the following code: ... sub setImage { my $self=shift; my $filename=shift; unless(-r $filename) { warn "File $filename not found"; return; } my $imgn=shift; my $operation=&URI::Escape::uri_escape_utf8( …
ZyX
  • 52,536
  • 7
  • 114
  • 135
2
votes
1 answer

HttpWebRequest referer header lost following redirect

When setting the referer header on an HttpWebRequest I'm seeing two different behaviors. On some sites the referer header will remain as each redirect is followed while on others the referer header is dropped after the first request. What would…
tribus
  • 1,110
  • 1
  • 9
  • 27
2
votes
3 answers

Get an access token from sign now REST APIs?

I followed this procedure. https://techlib.barracuda.com/CudaSign/RestEndpointsAPI This is my C# code to get an access token. string userData = "username=email@domain.com&password=mypassword&grant_type=password"; HttpWebRequest…
good-to-know
  • 742
  • 3
  • 15
  • 32
2
votes
0 answers

VBA WinHTTP Auto detect proxy settings

I am trying to send request to a web service from behind a proxy server in excel vba. How can i make my code auto detect proxy settings? Url = "www.example.com" Set WHTTP = CreateObject("WinHTTP.WinHTTPrequest.5.1") WHTTP.Open "GET", Url,…
Amelie Peter
  • 93
  • 3
  • 14
2
votes
1 answer

Sending xml request to url and receiving xml response back

I'm trying to send an xml request to a url and the response will also be an xml response. I know how to call a service endpoint from an MVC application but I'm not sure how to call this url and how to read what it will give me back. This is what I…
NNassar
  • 485
  • 5
  • 11
  • 25
2
votes
1 answer

System.Uri.CreateThis returning UriFormatException - The URI is empty ... but it isn't

Here's an odd one that has come up a couple of times today. I have a WPF app that does some posts to a server. I'm doing this using HttpWebRequest.Create. In this instance, the URL that is being used is hard-coded. Example: Dim Request As…
MattB
  • 2,203
  • 5
  • 26
  • 48
2
votes
1 answer

Making a HTTP request to API possible with VB/ASP classic?

Is it possible to make requests to a Web API with ASP classic? For example just something as simple as the Flickr API, or was this sort of thing not supported way back when?
Baxter
  • 2,416
  • 1
  • 22
  • 29
2
votes
1 answer

Basic question about request queues in IIS / ASP.Net

I have an ASP.Net application running under IIS 6. A simple page has two radio buttons and a submit button. If I select radio button "A" and submit the page, a lengthy PDF file is generated, which takes about a minute to build. If I select radio…
larryq
  • 15,713
  • 38
  • 121
  • 190
2
votes
4 answers

Performance, serve all CSS at once, or as its needed?

As far as I know, these days there are two main techniques used for including CSS in a website. A) Provide all the CSS used by the website in one (compressed) file B) Provide the CSS for required by the elements on the page that is currently being…
Dr. Frankenstein
  • 4,634
  • 7
  • 33
  • 48
2
votes
0 answers

Windows Phone 8.1 and HTTP POST Request

I'm trying to post data to a web server with such code: HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest; //request.CookieContainer = new CookieContainer(); //request.CookieContainer.Add(new Uri(uri), new…
2
votes
1 answer

Can a client dictate whether or not HttpContext is created?

We are getting a lot of hits from Googlebot and BingBot and it appears that none of these requests have an HttpContext. I originally thought that every http request will get a context which obviously is not the case so I'm trying to understand how…
kay.one
  • 7,622
  • 6
  • 55
  • 74
2
votes
9 answers

Java: Asynchronous task

For some of HTTP requests from clients, there're very complex business logic in server side. Some of these business logics doesn't require to response to the client immediately, like sending a email to somebody. Can I put those tasks in an…
Sawyer
  • 15,581
  • 27
  • 88
  • 124