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

Rest Post call with Authentication Token

I'm trying to send a Post request to SharePoint Online (Claims Based Auth Site) from my client application (WPF application). In this case it should be an update to a ListItem to change the 'Title' to 'Test'. I'm retrieving the CookieContainer via…
Mark
  • 3,273
  • 2
  • 36
  • 54
2
votes
2 answers

HttpWebRequest times out with multiple network adaptors enabled

On my Win7 PC I have a couple of virtual network adaptors that are used for VMWare server. My HttpWebRequest times out when I have these adaptors enabled. Should I really have to tell it which adaptor to bind to? HttpWebRequest request =…
Tim
  • 7,746
  • 3
  • 49
  • 83
2
votes
5 answers

401 Unauthorized on SECOND HttpClient/HttpWebRequest call

I have a application that uses the SharePoint 2010 REST API. In the process of creating an Item there are multiple request done after each other: 1 Call: Getting Items from List: Succes 2 Call: Create Item: 401 Unauthorized This is the same if I…
Koen H
  • 111
  • 2
  • 8
2
votes
0 answers

Youtube API upload - Incomplete Multipart body error

I'm trying to upload videos in Youtube through HttpWebRequest. Everything seems to be fine when uploading following the example given in API documentation. I see that request is being formed correctly, with content and token sent but I receive…
Blerim J
  • 148
  • 1
  • 7
2
votes
1 answer

HttpWebRequest throws exception in code but not browser

I'm currently writing an API that gets data from a Point of Sale System's web interface. So far, I haven't had any problems logging in and generating reports to get data from until this situation. In general, I can use the follow method to return an…
Ben
  • 134
  • 3
  • 9
2
votes
3 answers

c# WebResponse content length limit

I'm trying to fetch a big file from internet with C# with WebRequest. So far all other stuff that I have is working fine, but it appears that some part in the middle of the response I get is removed. I tried printing out the response.ContentLength…
Tengyu Liu
  • 1,223
  • 2
  • 15
  • 36
2
votes
0 answers

Why is this NUnit test failing?

This is an "extension" of the question here I am now running two instances of Visual Studio / the solution. I start one, and then in the other I access the context menu for this test: public enum HttpMethods { GET = 0, PUT, POST, …
B. Clay Shannon-B. Crow Raven
  • 8,547
  • 144
  • 472
  • 862
2
votes
3 answers

DownloadString and HttpWebResponse is not returning the full JSON content

I am trying to store a JSON response from the following url in a string. Most times I run the code, the last several characters of the JSON response are cut off. When you visit the url in a browser, the full JSON response is shown. Sometimes my…
James Lawruk
  • 30,112
  • 19
  • 130
  • 137
2
votes
2 answers

CacheManager.getCacheFileBaseDir() always returns null

I've been trying to use the CacheManager for caching some http requests but it failed every time with a nullpointer exception. After some digging I believe I found out why: CacheManager.getCacheFileBaseDir() always returns null so when I try to use…
Leon
  • 841
  • 3
  • 10
  • 21
2
votes
2 answers

Managing execution priorities and request expiry time in your web application

Some installations that run our applications can be under hefty stress on a busy day. Our clients ask us is there is a way to manage priorities in our application. For example, in a typical internet banking application, banks are interested in…
Dan
  • 11,077
  • 20
  • 84
  • 119
2
votes
1 answer

Compact framework - HttpWebRequest resource leak when offline

So this is a .NET CF 3.5 app, running on CE7. The problem is also visible in CE5. We use HttpWebRequests to query a server. When online, all seems well. When server is unavailable, we observe what appears to be a resource leak. Using the CF…
Nik
  • 2,718
  • 23
  • 34
2
votes
1 answer

Send files over HTTPWebRequest and receive on web-server from $_FILES

My .NET application sends a single simple text file to web-server over HttpWebRequest. But at the web-server side I am always getting an empty $_FILES array. I read all this questions and articles: POSTING MULTIPART/FORM-DATA USING .NET…
2
votes
2 answers

What is a good, free, AJAX PHP solution for creating a grid with right-click functionality?

I'd like to construct a grid, preferably with pagination built in, and do GETs POSTs etc from a right click submenu and have the grid update. We were using Ext but we found it do be too bulky for our uses. Can anyone recommend another library that…
stormist
  • 5,709
  • 12
  • 46
  • 65
2
votes
0 answers

HTTPS request/response in C#

I'm trying to view captcha from a site, but I screw something, because it is incorrect when I submit the answer, though I get the session and everything, so I decided to do it request by request, exactly the way they appear in fiddler, but it is…
2
votes
1 answer

Any advantage using HttpWebRequest.BeginGetRequest with AsycnWaitHandle.WaitOne()

I've run across some code in an ASP.NET app, and I'm wondering whether there is any practical difference between the following two snippets. Note, we are trying to send a request to a 3rd party endpoint and then use the response in what's rendered…
patmortech
  • 10,139
  • 5
  • 38
  • 50