Questions tagged [httpresponse]

An HTTP response is a network message which is made of a body and metadata in the form of headers, according to HTTP specification. May also refer an HttpResponse class in software frameworks and libraries that automates relevant functionality

From W3C specification:

   Response      = Status-Line               ;
                   *(( general-header        ;
                    | response-header        ;
                    | entity-header ) CRLF)  ;
                   CRLF
                   [ message-body ]          ;

See also:

3825 questions
594
votes
11 answers

Proper way to return JSON using node or Express

So, one can attempt to fetch the following JSON object: $ curl -i -X GET http://echo.jsontest.com/key/value/anotherKey/anotherValue HTTP/1.1 200 OK Access-Control-Allow-Origin: * Content-Type: application/json; charset=ISO-8859-1 Date: Wed, 30 Oct…
MightyMouse
  • 13,208
  • 8
  • 33
  • 43
361
votes
8 answers

Why should I use IHttpActionResult instead of HttpResponseMessage?

I have been developing with WebApi and have moved on to WebApi2 where Microsoft has introduced a new IHttpActionResult Interface that seems to recommended to be used over returning a HttpResponseMessage. I am confused on the advantages of this new…
Jason Roell
  • 6,679
  • 4
  • 21
  • 28
337
votes
10 answers

How to set HttpResponse timeout for Android in Java

I have created the following function for checking the connection status: private void checkConnectionStatus() { HttpClient httpClient = new DefaultHttpClient(); try { String url = "http://xxx.xxx.xxx.xxx:8000/GaitLink/" …
Niko Gamulin
  • 66,025
  • 95
  • 221
  • 286
257
votes
14 answers

Returning http status code from Web Api controller

I'm trying to return a status code of 304 not modified for a GET method in a web api controller. The only way I succeeded was something like this: public class TryController : ApiController { public User GetUser(int userId, DateTime…
ozba
  • 6,522
  • 4
  • 33
  • 40
218
votes
17 answers

Return content with IHttpActionResult for non-OK response

For returning from a Web API 2 controller, I can return content with the response if the response is OK (status 200) like this: public IHttpActionResult Get() { string myResult = ... return Ok(myResult); } If possible, I want to use the…
mayabelle
  • 9,804
  • 9
  • 36
  • 59
212
votes
12 answers

Return HTTP status code 201 in flask

We're using Flask for one of our API's and I was just wondering if anyone knew how to return a HTTP response 201? For errors such as 404 we can call: from flask import abort abort(404) But for 201 I get LookupError: no exception for 201 Do I need…
ingh.am
  • 25,981
  • 43
  • 130
  • 177
207
votes
3 answers

Difference between Pragma and Cache-Control headers?

I read about Pragma header on Wikipedia which says: "The Pragma: no-cache header field is an HTTP/1.0 header intended for use in requests. It is a means for the browser to tell the server and any intermediate caches that it wants a fresh…
saplingPro
  • 20,769
  • 53
  • 137
  • 195
183
votes
8 answers

.NET: Simplest way to send POST with data and read response

To my surprise, I can't do anything nearly as simple as this, from what I can tell, in the .NET BCL: byte[] response = Http.Post ( url: "http://dork.com/service", contentType: "application/x-www-form-urlencoded", contentLength: 32, …
172
votes
15 answers

What does it mean when an HTTP request returns status code 0?

What does it mean when JavaScript network calls such as fetch or XMLHttpRequest, or any other type of HTTP network request, fail with an HTTP status code of 0? This doesn't seem to be a valid HTTP status code as other codes are three digits in HTTP…
mike nelson
  • 21,218
  • 14
  • 66
  • 75
152
votes
5 answers

ASP.NET WebApi unit testing with Request.CreateResponse

I am trying to write some unit tests for my ApiController and faced some issues. There is a nice extension method called Request.CreateResponse that helps a lot with generating response. public HttpResponseMessage Post(Product product) { var…
asa
  • 1,827
  • 2
  • 15
  • 18
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…
139
votes
10 answers

How to get HTTP Response Code using Selenium WebDriver

I have written tests with Selenium2/WebDriver and want to test if HTTP Request returns an HTTP 403 Forbidden. Is it possible to get the HTTP response status code with Selenium WebDriver?
Ralph
  • 118,862
  • 56
  • 287
  • 383
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…
126
votes
13 answers

How do I return NotFound() IHttpActionResult with an error message or exception?

I am returning a NotFound IHttpActionResult, when something is not found in my WebApi GET action. Along with this response, I want to send a custom message and/or the exception message (if any). The current ApiController's NotFound() method does not…
Ajay Jadhav
  • 2,417
  • 4
  • 21
  • 26
116
votes
10 answers

Modify HTTP responses from a Chrome extension

Is it possible to create a Chrome extension that modifies HTTP response bodies? I have looked in the Chrome Extension APIs, but I haven't found anything to do this.
captain dragon
  • 1,289
  • 2
  • 9
  • 8
1
2 3
99 100