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

C# Not getting proper response from HttpWebResponse. Encoding?

I'm trying to fetch some webpages using the code below: public static string FetchPage(string url) { HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "GET"; req.UserAgent = "Mozilla/5.0…
pastapockets
  • 1,088
  • 2
  • 13
  • 20
2
votes
0 answers

Should a proxy return 500?

If an HTTP proxy throws an exception internally, what should it return to the client? Would a 500 be correct here?
BanksySan
  • 27,362
  • 33
  • 117
  • 216
2
votes
1 answer

Tracking Progress of HTTPWebRequest

How can I track upload progress of HTTPWebRequest? When I scattered Debug.WriteLines() to track which parts of my code takes the longest time, i found out the function that took the longest time is var res = req.GetResponse(); I could use…
Jiew Meng
  • 84,767
  • 185
  • 495
  • 805
2
votes
0 answers

Mono and WebRequest Speeds - A test

In mono 4.6.2 / linux, I'm noticing huge differences between the speed wget can download files, vs webclient.DownloadString, so I made a little test to investigate. Why is wget significantly faster than C#? From my own experiments, it's faster to…
user3791372
  • 4,445
  • 6
  • 44
  • 78
2
votes
2 answers

Attack all links with an ajax request

I've been trying create a pure function without jQuery or any other libraries to transform all links on my web app in an ajax request. But as you should know without success. Can someone tell me where I'm going wrong? function ajaxify() { var…
2
votes
3 answers

HTTPWebRequest waits for content to load by Ajax

I am trying to use httpWebRequest to get a complete web page, but the response that I get is not a complete web page because part of the web page is loaded by AJAX and this part takes a while (usually 10 - 30 seconds to load). Is there a way that I…
John Lam
  • 21
  • 1
  • 2
2
votes
2 answers

Call web api c# by passing oauth token along with parameter

I'm using custom oauth in web API for authentication. Now i want to call web api method from MVC controller. Web API method: public class UserController : ApiController { [Authorize(Roles = "Admin")] [HttpPost] [ActionName("UserById")] …
2
votes
2 answers

How to send JSON GET data with an HTTP request in C#

So I am having a lot of trouble with how to send the below JSON data in C# format. I know exactly how to do it in cURL, but I can't figure this out for the life of me. This request is essential to what I am doing and I really need to get it done.…
BenjaFriend
  • 664
  • 3
  • 13
  • 29
2
votes
4 answers

C# HttpWebRequest shows 404, but site is reachable in browser

I am trying to download an xml file from a website with c#, but I get an 404 on some urls. this is wired because they still work in the browser. Other urls still work without a problem. HttpWebRequest request = (HttpWebRequest) …
tom
  • 21
  • 1
  • 3
2
votes
1 answer

Performance of HttpWebRequest using POST

I have a small tool I use for testing a webservice. It can either call the webservice using POST or using GET. The code for using POST is public void PerformRequest() { WebRequest webRequest = WebRequest.Create(_uri); webRequest.ContentType =…
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
2
votes
2 answers

XML escaped characters

I am trying to send a POST request to add some content to an API box. The rules are that the body format should be XML(values must be XML-escaped), HTTP Method (post), requires authentication(yes), request content(content-type: "application/xml"…
vbNewbie
  • 3,291
  • 15
  • 71
  • 155
2
votes
2 answers

Getting HttpWebRequest to use ISO-8859-1 encoding for urlencoding

I'm having a problem getting HttpWebRequest to use ISO-8859-1 encoding for parametres in a webrequest, the problem is related to both POSTs and GETs. The problem in a nutshell is that any request parametres that contain non-ascii characters like Ö…
Grubsnik
  • 918
  • 9
  • 25
2
votes
0 answers

httpwebrequest using a pfx?

I'd like to reproduce the following chunk of vbscript using C#. sURL = "https://server/service.dll" sXML = "generated ticket" dim winHTTPReq: Set winHTTPReq =…
nerraga
  • 614
  • 7
  • 17
2
votes
1 answer

HttpWebResponse.Close Hangs for indefinite time

I am using HttpWebRequest to connect to a URL. This url keeps the connection open so that it can pump the data to the client over the internet. A custom pub/sub if you will. It is a simple GET. The response headers I get looks something like…
Jiho Han
  • 1,610
  • 1
  • 19
  • 41
2
votes
1 answer

searching a wsgi testing plugin in python

i was wondering what you'r using to test your python wsgi apps and which one is the most updated and easiest to setup. im on appengine python and i would like to start writing tests for my handlers. i've see gaeunit and nose-gae and if there are…
aschmid00
  • 7,038
  • 2
  • 47
  • 66