Questions tagged [system.net.httpwebrequest]

Provides an HTTP-specific implementation of the WebRequest, an abstract base class for the .NET Framework's request/response model for accessing data from the Internet class.

Provides an HTTP-specific implementation of the WebRequest, an abstract base class for the .NET Framework's request/response model for accessing data from the Internet class.

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.

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.

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.aspx

160 questions
15
votes
2 answers

HttpWebRequest in .NET Core 2.0 throwing 302 Found Exception

We are upgrading our application from .net framework to .net core 2.0. In it, we use a HttpWebRequest to contact a site with AllowAutoRedirect set to false. When the code executed request.GetResponse() The site will return a 302 response, which in…
10
votes
3 answers

Passing body content when calling a Delete Web API method using System.Net.Http

I have a scenario where I need to call my Web API Delete method constructed like the following: // DELETE: api/products/{id}/headers [HttpDelete("{id}/headers")] public void DeleteProductHeaders(int id, [FromBody] string query) { } The trick is…
Blake Rivell
  • 10,899
  • 23
  • 93
  • 182
8
votes
3 answers

FileNotFoundException: Could not load file or assembly 'System.Net.Http.WebRequest'

I've downloaded the latest .NET Framework and I'm working on .NET Core 2.0 Application on VS 2017 15.8.7. Here are the packages I've installed. using (var client = new PowerBIClient(new Uri(ApiUrl), tokenCredentials)) { } I'm getting…
MAK
  • 1,096
  • 14
  • 36
8
votes
1 answer

What's the alternative to WebRequestHandler in .NET Core?

I was using the WebRequestHandler for setting the CachePolicy and AuthenticationLevel in my full stack .NET application. Now I am migrating my application to .NET core and can't find an alternative to these properties or the WebRequestHandler. Any…
Amit
  • 83
  • 1
  • 5
8
votes
1 answer

The request was aborted: The request was canceled. No solution works

Our console applications are making hundreds of WebRequests to Facebook every minute (with using multiple apps and hundreds of access tokens). Now, they started to fail with the exception message in the title ("The request was aborted: The request…
8
votes
2 answers

Establishing SSL\TLS connection (X509Chain.Build()) takes too long

I found that when I use HttpWebRequest to establish SSL\TLS connection, it takes near 30s when calling request.GetRequestStream() when I've enabled tracing with stacktrace enabled, I found that 2s goes to find poxy, so I've disabled it in…
hkurabko
  • 651
  • 1
  • 7
  • 9
7
votes
1 answer

HttpResponseMessage unavailable in App_Code folder of VS 2012 project

I am writing a Web API project (MVC architecture). I have a utility class with methods that returns an HttpResponseMessage. If this class is placed in a Utility folder everything works. If I attempt to place the class within the App_Code folder,…
6
votes
1 answer

Using GoogleApisClient ServiceAccountCredential calling RequestAccessTokenAsync throws Exception

Background: I have set up a Service Account for my project on Google Developer Console and using the Service Account Email, the Certificate and the secret password and following the example provide in the GoogleAPisSample Plus.ServiceAccount. The…
6
votes
1 answer

What is the difference between CookieContainer and Response.Cookies collection?

I have been doing some research on this and I couldn't find a straight answer. Are there some cookies stored in the container that I can't get to using the Response.Cookies collection? How are cookies handled between requests using these objects?…
Thomas
  • 5,618
  • 6
  • 40
  • 79
6
votes
1 answer

Web Api: System.Net.Http version 2.0.0.0 not found

When I install the NuGet package for WebApi, it gives me version 1.0.0.0 of System.Net.Http, yet it references version 2. I cannot seem to find version 2 for the life of me. When I download .net 4.5 I get System.Net.Http version 4.0.315.x, but I…
5
votes
1 answer

Getting "Stream not readable" when reading HttpWebResponse

I'm trying to "screen scrape" some data I have a request as follows (from fiddler) POST http://fallenlondon.storynexus.com/Auth/EmailLogin HTTP/1.1 Content-Type: application/x-www-form-urlencoded Referer:…
Taoist
  • 321
  • 3
  • 11
4
votes
2 answers

Open Html code in browser

i have a c# application, which calls an API and the response is in HTML format. i don't want to save the HTML code to a file but i want to open that html code in a browser i am able to display if the HTML is saved in a file using…
Sumeshk
  • 1,922
  • 19
  • 32
4
votes
1 answer

Get IE's default proxy with DefaultWebProxy

I've read through pretty much all the documentation I can find but I'm yet to find a simple working example of how to get IE's default proxy settings using DefaultWebProxy(). This code seems to compile and work but how do I then go ahead and get the…
Paul Matthews
  • 2,016
  • 5
  • 20
  • 28
3
votes
1 answer

Get body text from an HttpWebRequest object?

I have a (legacy) method in my codebase which generates and returns a ready-to-send HTTP POST message as a System.Net.HttpWebRequest object: public HttpWebRequest GetHttpWebRequest(string body, string url, string contentType) { HttpWebRequest…
Jon Schneider
  • 21,628
  • 17
  • 129
  • 157
3
votes
2 answers

In c#( .net) system.net.http, how to get the response.statuscode as an int? Not to use HttpWebRequest and HttpWebResponse

var hcHandler = new HttpClientHandler(); //hcHandler.AllowAutoRedirect = false; var hc = new HttpClient(hcHandler); hc.DefaultRequestHeaders.Add("user-agent", "Mozilla/5.0 (compatible; MSIE 10.0; Windows NT 6.2;…
1
2 3
10 11