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

WebRequest Caching Windows Phone 7

From what I understand, the HttpWebRequest class always cache the downloaded data. Now I don't mind this, but after a throughly reparsing the same URL through HttpWebRequest during the app duration, I've noticed that the data becomes corrupted (as…
Daniel Clark
  • 615
  • 2
  • 9
  • 17
2
votes
1 answer

WPF HTTPWebRequest The underlying connection was closed: An unexpected error occurred on a receive

Firstly, there are a number of other similar questions and I have read them all and they have a similar problem however they differ from my problem: In a WPF client application I am making several HttpWebRequests to various websites. On one…
2
votes
2 answers

How to introduce a delay between webrequests to a site in C#?

I am making multiple requests to a website. How can I introduce a delay between requests to slow down my process? Is there a method that allows me to just cause the thread to wait for X seconds before proceeding?
super9
  • 29,181
  • 39
  • 119
  • 172
2
votes
2 answers

Why are HttpWebRequest and WebBrowser getting different HTML source code?

I am trying to get the source code from a webpage. The WebBrowser control is giving me the information that I am looking for. However, I want to use HttpWebRequest, but its giving me different source code than the WebBrowser DocumentText. Can anyone…
Nasim
  • 21
  • 1
  • 2
2
votes
1 answer

How can I check passwords against the 'haveibeenpwned Pwned Passwords' from PowerShell?

I'd like to be able to use the Pwned Passwords list provided by Troy Hunt's have I been pwned service. The service is described in his Introducing 306 Million Freely Downloadable Pwned Passwords blog post. The API uses an HTTP Not Found 404 status…
Martin Hollingsworth
  • 7,249
  • 7
  • 49
  • 51
2
votes
0 answers

Making HttpWebRequest with "If-None-Match" Header (Etag)

I am trying do download data from web with normall httpwebrequest (work on most url), but server send me unexpected response, like this HTTP/1.1 200 OK Server: nginx Date: Thu, 10 Aug 2017 03:59:39 GMT Content-Type: application/json Content-Length:…
arthur
  • 47
  • 6
2
votes
1 answer

Retrieve E-mail from server (pop3) by date for filtering on subject or body in C#

I have a piece of monitoring software I am writing which needs to retrieve e-mails sent to an address for a certain day so that I can filter them by a regex in the subject or body. I don't need to retrieve the entire message, only the subject and…
Josh
  • 16,286
  • 25
  • 113
  • 158
2
votes
3 answers

Why use HttpClient over HttpWebRequest for synchronous requests

In my scenario, I have to send data from one web application to a webapi which is an effective data store. The requests are necessarily synchronous and I most definitely want an Exception thrown if something goes awry as it means a critical part of…
DiskJunky
  • 4,750
  • 3
  • 37
  • 66
2
votes
2 answers

Codemetric optimized httpwebrequest in C#

the problem is the httpwebrequest method in my c# program. visual studio gives it a metric of 60, thats pretty lame.. so how can i program it more efficient? (: my actual code: public string httpRequest(string url) { HttpWebRequest…
Omegavirus
  • 277
  • 4
  • 16
2
votes
1 answer

copy multiple remote files to another remote file via HttpWebRequest C#

I have a remote folder with n files and I need to copy content in another remote file. I guess it can be done through streams, and this is what I tried: WebRequest destRequest = WebRequest.Create(destFile); destRequest.Method…
Fabrizio Morello
  • 335
  • 1
  • 5
  • 18
2
votes
2 answers

Chrome doesn't open url properly using process.start c#

I'm trying to do some work with fakemailgenerator, the url goes well with httpwebrequest and gets printed by MessageBox.Show properly, here is the piece of code with the problem, btw there no errors or exeptions. //FOR EXAMPLE…
nomorehere
  • 332
  • 2
  • 12
2
votes
3 answers

posting none-english data with HttpWebRequest

The web site is in hebrew with Windows-1255 encoding. Using Firefox's Tamer Data extension, i see that one of the Post parameters is: +++++++++%E4%FA%E7%E1%F8+++++++++ using this table I translated it to hebrew: +++++++++התחבר+++++++++ Now, I…
jullin
  • 633
  • 2
  • 12
  • 21
2
votes
2 answers

Reactive Extensions clean up

If you have a long chain of calls using rx such as: var responses = collectionOfHttpRequests.ToObservable() .FromAsyncPattern(req.BeginGetResponse, req.EndGetResponse) .Select(res => res.GetResponseBodyString()) // Extension method to get the body…
amc
  • 121
  • 1
  • 2
  • 4
2
votes
1 answer

C# Speed up parallel webrequests using async

so I have this code: This is the main function,a parallel for loop that iterates through all the data that needs to be posted and calls a function ParallelOptions pOpt = new ParallelOptions(); pOpt.MaxDegreeOfParallelism = 30; …
2
votes
3 answers

How to check if user have sucessfully logged in webrequest

I have written a code and executes well I provide it username and password it implements POST but i dont know that login is sucessfull or not is there any way to check that? var strId = UserName.Text; var strName = UserPass.Text; var encoding = new…
Afnan Bashir
  • 7,319
  • 20
  • 76
  • 138