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

Pass value and redirect user from ASP.NET to PHP

I have a scenario here whereby, on ASP.NET server side (domain A), some data (string data) needs to be pass over to PHP server side (domain B), and then the user will be redirected from Domain A to Domain B. Can this be done over http? Or should it…
j.chan22
  • 23
  • 2
2
votes
1 answer

HttpWebRequest no accepting cookies C#

I'm having an issue with HttpWebRequest accepting cookies, this is my code: HttpWebRequest req= (HttpWebRequest)WebRequest.Create("https://www.companyabc.com/security?action=authenticate"); req.CookieContainer = new…
John Smith
  • 41
  • 1
  • 10
2
votes
2 answers

Wrapper class for HttpGet / Post in Java?

Sorry, I'm quite new to Java. I've stumbled across HttpGet and HttpPost which seem to be perfect for my needs, but a little long winded. I have written a rather bad wrapper class, but does anyone know of where to get a better one? Ideally, I'd be…
Tim Green
  • 2,028
  • 1
  • 17
  • 19
2
votes
2 answers

How do Test HttpWebRequest Depended method?

I have this class: public class RestClient { public RestClient() { } protected virtual HttpWebRequest CreateHttpWebRequest(Uri uri) { return (HttpWebRequest)HttpWebRequest.Create(uri); } /// ///…
2
votes
0 answers

.NET How to Send WebRequest on Specified IP address in same domain

I have a problem. Whenever I'm sending WebRequest to https://myaddress.com, it resolves to the wrong IP address (this domain has several IP adresses). How can I specify IP address, which I want to send the WebRequest to? var uri = new Uri(url); var…
Danil Shaykhutdinov
  • 2,027
  • 21
  • 26
2
votes
1 answer

.net Unconsistency in Request Browser version

i had created an empty c# web site with just one page with Request.Browser.Version & UserAgent output on it. Then hit it with different Chrome versions using "User-Agent Switcher" Chrome extension. For time to time, though the Request.UserAgent is…
Ariel K
  • 61
  • 6
2
votes
2 answers

Automate picture downloads from website with authentication

My intention is to automate the downloading of all pictures in a website that requires a login (a web-form based login I think) The website: http://www.cgwallpapers.com The login url: http://www.cgwallpapers.com/login.php The registered members url:…
ElektroStudios
  • 19,105
  • 33
  • 200
  • 417
2
votes
1 answer

Stream does not support seek operations

I'm trying to POST to a website where the only parameter needed is "description." I believe it has something to do with the way that I am encoding my data. Am I missing something/going about this the wrong way? string postData =…
user2836292
  • 305
  • 2
  • 5
  • 13
2
votes
2 answers

Using C# to HttpPost data to a web page

I want to log in into a website using C# code. Here's the html code of the example form:
druffmuff
  • 51
  • 5
2
votes
0 answers

How to Completely Emulate Web Browser Using HttpWebRequest with Headers?

For a long time i've been trying to emulate web browser using HttpWebRequest. Using most known or basic headers like : User Agent - Accept(content type) - Protocol Version - Accept (language) - Referer - Method - Keep Alive.. and for sure…
Dr.Vision
  • 85
  • 1
  • 5
  • 14
2
votes
4 answers

Simulating connection problems for .NET HttpWebRequest

Are there ways to programmatically simulate connection problems (slow connection, response does not complete, connection gets dropped, etc.) when using the HttpWebRequest class? Thanks EDIT: To elaborate more, I need this for debugging but would…
Fung
  • 7,530
  • 7
  • 53
  • 68
2
votes
2 answers

Error 500 Web Request Can't Scrape WebSite

I have no problem accessing the website with a browser, but when I programmatically try to access the website for scraping, I get the following error. The remote server returned an error: (500) Internal Server Error. Here is the code I'm using.…
Trey Balut
  • 1,355
  • 3
  • 19
  • 39
2
votes
1 answer

Invoking another URL

string url = "http://foo.com/bar?id=" + id + "&more=" + more; HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); HttpWebResponse response = (HttpWebResponse)request.GetResponse(); I m trying make a call to another server,…
DarthVader
  • 52,984
  • 76
  • 209
  • 300
2
votes
3 answers

How to send HttpWebRequest and receive answer to check internet in c#?

I'm trying to make an app that check internet connection (and integrity of an special site) using httpwebrequest. I found this code after researching but can't complete it and don't know if it is true: WebRequest myRequest =…
Mohammad H
  • 785
  • 2
  • 10
  • 25
2
votes
2 answers

Why is .NET Post different from CURL? broken?

NOTE: I fixed the user agent problem and i also added in an extra byte to match the content length. No luck however. I dont understand this. I ran this code below and the result json string was the link is expired (meaning invalid). However the curl…
user261192
  • 77
  • 5