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

C# .NET Uploading file to a web form using HttpWebRequest

Does anyone have a working example using HttpWebRequest in C# to submit a file from the local drive to a multipart/form-data web form?
user42931
  • 1,135
  • 2
  • 10
  • 12
2
votes
0 answers

Handling large pac files in C# HTTPWebRequest

I currently have a C# application which makes frequent web requests that have to potentially go through proxy authentication. In this situation, a large PAC file (200kb+) is used to automatically configure the proxy and is stored on a remote…
2
votes
0 answers

ServicePoint.BindIPEndPointDelegate doesn't work

in my program in c#, i need to connect to a website by a specified ip.for this I use ServicePoint.BindIPEndPointDelegate,but it doesn't work. I searched and found this: when server supports ipv6, we try to establish connection with server using its…
mansureh
  • 39
  • 7
2
votes
3 answers

Why might HttpOpenRequest fail with error 122?

The following code fRequestHandle = HttpOpenRequestA( fConnectHandle, "POST", url.c_str(), NULL, NULL, NULL, INTERNET_FLAG_RELOAD|INTERNET_FLAG_NO_CACHE_WRITE, …
David Sykes
  • 48,469
  • 17
  • 71
  • 80
2
votes
0 answers

HttpWebRequest vs RestSharp which one should I use to make Rest call to Azure and Amazon Services

I have to make some Rest call to Azure Storage api as well as some Amazon service. I can see there exists lots of options(HttpWebRequest, WebClient, HttpClient, RestSharp) that i can use to make REST call. I have used HttpClient several times…
2
votes
2 answers

The remote name could not be resolved "www.google.com"

I am in a company network. In this network i can't ping external websites by IP. I can only call them by url like the browser does. Thats why i use WebRequest. When i try to call "www.google.com" i got a "remote name could not be resolved…
Shadow
  • 31
  • 1
  • 5
2
votes
0 answers

C# HttpWebRequest Cache

In my app I build a GET request intended to return a response from cache whenever the contents are the same as on the server. HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Method = "GET"; …
Max
  • 21
  • 3
2
votes
4 answers

How to prevent just anyone sending a request to my web service

I have an app in C# which serializes an object into xml into a http stream to my server. The server has some php which runs a stored procedure in mysql with the xml data as its only parameter. The problem is that someone could very easily just send…
Jimmy
  • 21
  • 1
2
votes
0 answers

HttpWebRequest hanging on third call

I have a method which I am using to login to a website. Each time, this method creates a new Webrequest and Webresponse, it works fine for the first 2 times. However, the third time I call it, it hangs (On the line using (Stream stream =…
wingerse
  • 3,670
  • 1
  • 29
  • 61
2
votes
2 answers

Silverlight 4 HttpWebRequest throwing ProtocolViolationException

I'm invoking a REST service via http which returns a stream as the response. My client code looks like so: Uri uri = new Uri(remoteAddress); var webRequest = (HttpWebRequest)WebRequest.Create(uri); …
Abhijeet Patel
  • 6,562
  • 8
  • 50
  • 93
2
votes
0 answers

"The remote certificate is invalid according to the validation procedure" occuring from time to time

The C# service is using RestSharp to fetch some data from the given url. The remote site uses ssl. The task is recurring on every 5 minutes and doing fine. However, on every few hours the service is getting: System.Net.WebException: The…
manda
  • 228
  • 1
  • 10
2
votes
2 answers

AWS API Gateway Signature

I am trying to sign my requests to the amazon gateway. But every time when I try to send a POST request it tells me that my signature has been expired. Any ideas will be appreciated.
2
votes
1 answer

Getting the response of an instagram url

I am trying to integrate a third party application. The procedure is as follows: I have the url of the third party (login required) I have to paste this in the browser. The result of this will be an url in the browser. For example: the url stands…
Venkat
  • 1,702
  • 2
  • 27
  • 47
2
votes
1 answer

HttpWebRequest force new connection

I want to download large file from limited-transfer server using several threads with HttpWebRequest.AddRange(int, int). The problem is that all my threads but one get blocked on GetResponse(), probably becouse they want to reuse the connection of…
noisy cat
  • 2,865
  • 5
  • 33
  • 51
2
votes
1 answer

How to use client's IP when doing HttpWebRequest in ASP.NET

In my website when I am making HttpWebRequest to another website, ASP.NET uses server's IP. Is there a way to use client's IP to make HttpWebRequest?