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

How to set response filename without forcing "save as" dialog

I am returning a stream in some response setting the appropriate content-type header. The behavior I'm looking for is this: If the browser is able to render content of the given content type then it should display it in the browser window. If the…
137
votes
8 answers

WebClient vs. HttpWebRequest/HttpWebResponse

It seems to me that most of what can be accomplished with HttpWebRequest/Response can also be accomplished with the WebClient class. I read somewhere that WebClient is a high-level wrapper for WebRequest/Response. So far, I can't see anything that…
Dan
  • 11,077
  • 20
  • 84
  • 119
132
votes
5 answers

Uses of content-disposition in an HTTP response header

I have found the following asp.net code to be very useful when serving files from a database: Response.AppendHeader("content-disposition", "attachment; filename=" + fileName); This lets the user save the file to their computer and then decide how…
101
votes
6 answers

How to get error information when HttpWebRequest.GetResponse() fails

I am initiating an HttpWebRequest and then retrieving it's response. Occasionally, I get a 500 (or at least 5##) error, but no description. I have control over both endpoints and would like the receiving end to get a little bit more information. …
Trevor
  • 13,085
  • 13
  • 76
  • 99
87
votes
5 answers

How to convert WebResponse.GetResponseStream return into a string?

I see many examples but all of them read them into byte arrays or 256 chars at a time, slowly. Why? Is it not advisable to just convert the resulting Stream value into a string where I can parse it?
Joan Venge
  • 315,713
  • 212
  • 479
  • 689
60
votes
5 answers

Is there an enum for the ContentType property on a HttpWebResponse ("text/plain", "application/octet-stream" etc.)?

The closest thing I could find was System.Net.Mime.MediaTypeNames but that doesn't seem to have everything (like json) since it seems to be more focused around email attachments.
will
  • 3,975
  • 6
  • 33
  • 48
57
votes
3 answers

Authentication failed because the remote party has closed the transport stream exception when getting a response from webservice

I am calling a third party service and when I ask for a response it throws out an exception that says "Authentication failed because the remote party has closed the transport stream exception". I think that there is a problem in sending…
Chirag K
  • 2,394
  • 2
  • 16
  • 23
46
votes
5 answers

C# How to set HttpClient Keep-Alive to false

I had a low performance problem with HTTP requests on .NET. The HTTP GET request to a REST API on the localhost took about 500 ms to complete. I spent a lot of time to fix it. I have tried many ways: HttpClient, HttpWebRequest, WebClient and…
Vaskrol
  • 471
  • 1
  • 4
  • 8
41
votes
2 answers

How to process WebResponse when .NET throws WebException ((400) Bad Request)?

I'm using Facebook Graph Api and trying to get user data. I'm sending user access token and in case this token is expired or invalid Facebook returns status code 400 and this response: { "error": { "message": "Error validating access…
Burjua
  • 12,506
  • 27
  • 80
  • 111
40
votes
3 answers

Get HTTP requests and responses made using HttpWebRequest/HttpWebResponse to show in Fiddler

Is there any way I can hook Fiddler up to capture requests and responses made using .NET HttpWebRequest and HttpWebResponse?
Fung
  • 7,530
  • 7
  • 53
  • 68
33
votes
12 answers

How to loop through WebHeaderCollection

How do you loop through a WebHeaderCollection got from HttpWebResponse in Windows phone 7 to get keys and values? We've tried Enumerator.Current; with this, we are only getting the keys, not the values. We are doing this to get a redirected URL.
gusaindpk
  • 1,243
  • 2
  • 13
  • 31
32
votes
3 answers

reading HttpwebResponse json response, C#

In one of my apps, I am getting the response from a webrequest. The service is Restful service and will return a result similar to the JSON format below: { "id" : "1lad07", "text" : "test", "url" : "http:\/\/twitpic.com\/1lacuz", …
tugberk
  • 57,477
  • 67
  • 243
  • 335
27
votes
2 answers

What is the timespan type of max-age in the HTTP response header? Seconds, minutes?

In the HTTP response header for my website it is returning a header that contains the following value. "Cache-Control: max-age=3600" Is 3600 in seconds or minutes?
Paul Mendoza
  • 5,709
  • 12
  • 53
  • 82
24
votes
4 answers

How to parse HttpWebResponse.Headers.Keys for a Set-Cookie session id returned

I'm trying to create an HttpWebRequest/HttpWebResponse session with an ASP.NET website to later parse an HTML form through url params (this part I know how to do), but I do not understand how to parse and set a cookie such as the session id. In…
Maxim Zaslavsky
  • 17,787
  • 30
  • 107
  • 173
22
votes
3 answers

How to set useUnsafeHeaderParsing in code

I am getting the following exception: The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF From this question: HttpWebRequestError: The server committed a protocol violation. Section=ResponseHeader…
Barka
  • 8,764
  • 15
  • 64
  • 91
1
2 3
70 71