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

Does HttpWebRequest need to be closed? How

I have a small program that keep posting some data (4MB) to remote server. Each time when an internal 4MB buffer is full, I create a new HttpWebRequest, call BeginGetRequestStream/EndGetRequestStream, write data to stream, close it, and done.…
codewarrior
  • 723
  • 7
  • 22
2
votes
2 answers

Stream Read/Write Timeout causes Invalid Operation Exception

I am trying to get a request from an API using: RestClient client = new RestClient("https://gds.eligibleapi.com/v1.5/coverage/all?api_key=" + apiSecret + "&payer_id=" + payerID + "&service_provider_organization_name=" + providerOrgName +…
Rinktacular
  • 1,116
  • 3
  • 19
  • 45
2
votes
0 answers

C# AccessViolationException was unhandled

I write down a multi-threading program to get page info.Debugging this program some time ,it will show this error "Access Violation Exception was unhandled.Attempted to read or write protected memory. This is often an indication that other memory is…
E.Tarrent
  • 89
  • 6
2
votes
2 answers

Xamarin Form HttpClient Stuck

I'm trying to get response from soundcloud API. Here is my code. public static async Task GetTheGoodStuff() { var client = new HttpClient(new NativeMessageHandler()); var response = await…
2
votes
2 answers

Debug .NET HttpWebRequest

Visual Studio 2010 .NET 3.5 Is there any tool that can trace the http request/response that send between my web application to the remote server? I use Wireshark or Fiddler, but both seem not so fit. Please advise, thanks.
Stan
  • 37,207
  • 50
  • 124
  • 185
2
votes
0 answers

webrequests with Binding different IPs using BindIPEndPointDelegate does not result in multiple ServicePoints for same host in multi-thread

Category: Throughput Increment Scenario: Multiple HttpWebRequests need to be send through different ethernet adapters to the same host. Keys to Remember: Requests are going to same host. There is a built in limit on per-host basis as…
devprashant
  • 1,285
  • 1
  • 13
  • 23
2
votes
2 answers

HttpWebRequest takes a long time to send when there are a bunch at once from client

I am attempting to load-test a Comet-ish server using a C# load testing client that creates many HttpWebRequests (1000+). I am finding that after a few minutes, randomly, the server takes a long time to receive some of the requests. The client…
evilfred
  • 2,314
  • 4
  • 29
  • 44
2
votes
0 answers

Why is Basic Auth client default behaviour to require 401 before sending credentials?

I'm currently trying to understand some technical implications of using HTTP Basic Auth for an HTTP API sketch. What I noticed is that both the C# HTTP Web Request as well as wget will - by default - send a request without credentials first,…
Martin Ba
  • 37,187
  • 33
  • 183
  • 337
2
votes
2 answers

Windows Form vs Unity3D HttpWebRequest Performance

I am working on a simple program that grabs image from a remote IP camera. After days of research, I was able to extract JPEG images from MJPEG live stream with sample codes I got. I did a prototype with using Windows Form. With Windows Form, I…
Programmer
  • 121,791
  • 22
  • 236
  • 328
2
votes
1 answer

one connection multiple requests Rest Service

How can one issue multiple requests using the same service? I have created a static httpWebRequest: private static HttpWebRequest request; //private static StreamReader streamReader; //private StreamWriter streamWriter; public…
2
votes
0 answers

How to accept and read data from httpcontext in php?

I want to add a page written in PHP to handle HTTP Requests, and to answer them. All I want is a page that does like below code: <%@ WebHandler Language="C#" Class="Handler" %> using System; using System.Web; public class Handler :…
2
votes
0 answers

How do I programmatically find whether the intermediate certificate was served by the web server?

My C# code uses HttpWebRequest to send requests to a web service via HTTP over SSL (https:// prefixed URLs). The service has it's coolservice.example.com certificate which is signed by certificate authority intermediate certificate which is in turn…
sharptooth
  • 167,383
  • 100
  • 513
  • 979
2
votes
1 answer

WebRequest does not contain a definition for 'GetResponse' for Windows 10 Universal App

I download a Console Application on GitHub and works fine. But I want to translate this C# Console Application to a Universal Windows 10 Application. The error on Visual Studio: Web Request does not contain a definition for... This is the code: …
2
votes
1 answer

.NET WebRequest Throttling

I'm using C# .NET 4 and MSSQL. The code uses WebRequest to download the html of different websites. The code is multi threaded. I want to limit the number of requests per mintue for a pre-defined list of domains. For example Domain: www.domain1.com…
RuSh
  • 1,643
  • 7
  • 25
  • 39
2
votes
1 answer

c# .NET 4.5 HttpWebRequest for portable crossplatforms

I cannot change user agent of HttpWebRequest: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Headers[HttpRequestHeader.UserAgent] = "test"; Always throw exception. Someone have idea how solve this?