Questions tagged [httpwebresponse]

Provides an HTTP-specific implementation of the WebResponse class

The HttpWebRequest class provides support for the properties and methods defined in the WebRequest class and for additional properties and methods that enable the user to interact directly with servers using HTTP.

1062 questions
11
votes
1 answer

Should one dispose of the WebResponse reference in WebException, if raised from WebClient?

Related question: WebClient in .Net not releasing socket resources While debugging a resource leak issue, I noticed that System.Net.WebException (a non-disposable type) contains a reference to System.Net.WebResponse (a disposable type). I am…
Steve Guidi
  • 19,700
  • 9
  • 74
  • 90
11
votes
3 answers

Sockets in C#: How to get the response stream?

I'm trying to replace this: void ProcessRequest(object listenerContext) { var context = (HttpListenerContext)listenerContext; Uri URL = new Uri(context.Request.RawUrl); HttpWebRequest.DefaultWebProxy = null; HttpWebRequest…
Tute
  • 6,943
  • 12
  • 51
  • 61
11
votes
3 answers

HttpStatusCode to readable string

HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync(); HttpStatusCode statusCode = response.StatusCode; In this code statusCode.ToString() returns for example "BadRequest" but I need "Bad Request" I saw arcticles about…
Vitaliy
  • 281
  • 1
  • 2
  • 12
11
votes
3 answers

How do I use HttpClient PostAsync parameters properly?

So I am working on writing an extension class for my project using HttpClient since I am moving over from HttpWebRequest. When doing the POST request, how do I send a normal string as a parameter? No json or anything just a simple string. And this…
Aleks Slade
  • 211
  • 1
  • 2
  • 11
10
votes
3 answers

Optimal buffer size for response stream of HttpWebResponse

What's the optimal buffer size to use with a stream from HttpWebResponse.GetResponseStream()? Online examples vary from 256b to as much as 5Kb. What gives? I guess buffer sizes might be situational. If so what are the situations to use what type of…
Fung
  • 7,530
  • 7
  • 53
  • 68
10
votes
3 answers

powershell httpwebrequest GET method cookiecontainer problem?

I'm trying to scrape a website that has user authentication. I am able to do a POST to send my login and stores a cookie. However, after the login I get a 403 error when trying to access the protected page. $url =…
10
votes
2 answers

Getting JSON data from a response stream and reading it as a string?

I am trying to read a response from a server that I receive when I send a POST request. Viewing fiddler, it says it is a JSON response. How do I decode it to a normal string using C# Winforms with preferably no outside APIs. I can provide additional…
Chris Altig
  • 680
  • 3
  • 8
  • 22
9
votes
3 answers

Getting Error "The remote server returned an error: (403) Forbidden" when screen scraping using HttpWebRequest.GetResponse()

We have a tool which checks if a given URL is a live URL. If a given url is live another part of our software can screen scrap the content from it. This is my code for checking if a url is live public static bool IsLiveUrl(string url) { …
9
votes
3 answers

Concurrency Limit on HttpWebRequest

I am writing an application to measure how fast I can download web pages using C#. I supply a list of unique domain names, then I spawn X number of threads and perform HTTPWebRequests until the list of domains has been consumed. The problem is…
Kam Sheffield
  • 1,231
  • 1
  • 14
  • 16
9
votes
6 answers

Getting "underlying connection was closed" on HttpWebRequest

I have an application written in VB.NET (NOT asp.net, it is a Windows Console app). I am trying to call a url (an html page) and get back the response into a string. The response is straight JSON, no html tags whatsoever. It opens with { and closes…
eidylon
  • 7,068
  • 20
  • 75
  • 118
9
votes
2 answers

How to read HTTP header from response using .NET HttpWebRequest API?

My app currently uses OAuth to communicate with the Twitter API. Back in December, Twitter upped the rate limit for OAuth to 350 requests per hour. However, I am not seeing this. I am still getting 150 from the account/rate_limit_status method. I…
Ryan Alford
  • 7,514
  • 6
  • 42
  • 56
9
votes
3 answers

c# HttpWebResponse Header encoding

I have the following problem. I contact an address which I know employs a 301 redirect. using HttpWebRequest loHttp = (HttpWebRequest)WebRequest.Create(lcUrl); and loHttp.AllowAutoRedirect = false; so that I am not redirected. Now I get the header…
Alexandros B
  • 1,881
  • 1
  • 23
  • 36
9
votes
2 answers

Access response payload/data from within a chrome extension

I am working on a project where it is required to track requests "ajax ones" from certain site, access response payload for some of those requests and act upon them. So far i managed to track requests and access their headers using the webRequest…
8
votes
2 answers

Should WebException.Response.GetResponseStream() be close / disposed?

When I catch a .NET WebException, should I close / dispose the Response.GetResponseStream()? The MSDN example does not close or dispose anything in the exception. Many SO answers recommend disposing the response and / or the stream. I disposed the…
Peter
  • 3,322
  • 3
  • 27
  • 41
8
votes
4 answers

How to read the response stream before the Http response completes

When making a request using HttpWebRequest object, I need to call the method GetResponse() to send the request and get the response back. The problem with this method is that it doesn't return the response object until all data has been received.…
user434917
1 2
3
70 71