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
33
votes
4 answers

Web API Best Approach for returning HttpResponseMessage

I have a Web API project and right my methods always returns HttpResponseMessage. So, if it works or fails I return: No errors: return Request.CreateResponse(HttpStatusCode.OK,"File was processed."); Any error or fail return…
VAAA
  • 14,531
  • 28
  • 130
  • 253
32
votes
2 answers

Express 4.14 - How to send 200 status with a custom message?

How can I send status and message in express 4.14? For: res.sendStatus(200); I get OK on my browser but I want it to display a custom message such as: Success 1 res.sendStatus(200); res.send('Success 1'); Error: Error: Can't set headers after they…
Run
  • 54,938
  • 169
  • 450
  • 748
32
votes
2 answers

Configuring response timeout in Apache JMeter

I am trying to check if a particular HTTP request's response time is over 30 seconds, and if it is, then mark it as failed and stop the thread. Sometimes I can see response times close to 80 seconds, an no browser is waiting that long for a response…
32
votes
1 answer

Web API: Content in HttpResponseMessage

In one of my Get request, I want to return an HttpResponseMessage with some content. Currently I have it working as follows: var header = new MediaTypeHeaderValue("text/xml"); Request.CreateResponse(HttpStatusCode.OK, myObject, header); However,…
Karan
  • 14,824
  • 24
  • 91
  • 157
30
votes
4 answers

Proper HTTP headers for login success / fail responses?

Are there any standards for using HTTP headers for login success / fail responses?
unicorn_crack
  • 1,059
  • 1
  • 8
  • 19
29
votes
3 answers

How do I set multiple headers using PostAsync in C#?

I have some working code: using (var client = new HttpClient()) { HttpResponseMessage response; response = client.PostAsync(Url, new StringContent(Request, Encoding.UTF8, header)).Result; } // the above works fine for a simple header, e.g.…
n as
  • 609
  • 3
  • 7
  • 12
29
votes
5 answers

How to print out returned message from HttpResponse?

I have this code on my Android phone. URI uri = new URI(url); HttpPost post = new HttpPost(uri); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(post); I have a asp.net webform application that has in…
chobo2
  • 83,322
  • 195
  • 530
  • 832
29
votes
8 answers

django: raise BadRequest as exception?

Is it possible to raise BadRequest as exception in django? I have seen that you can raise a 404 [1]. Use case: in a helper method I load a json from request.GET. If the json was cut since the browser (IE) cut the url, I would like to raise a…
guettli
  • 25,042
  • 81
  • 346
  • 663
27
votes
9 answers

Why are .docx files being corrupted when downloading from an ASP.NET page?

I have this following code for bringing page attachments to the user: private void GetFile(string package, string filename) { var stream = new MemoryStream(); try { using (ZipFile zip = ZipFile.Read(package)) { …
Victor Rodrigues
  • 11,353
  • 23
  • 75
  • 107
26
votes
1 answer

Differences between Response.End() and Response.Flush()

I have code like this: context.HttpContext.Response.Clear(); context.HttpContext.Response.Write(htmlString); context.HttpContext.Response.End(); But when pages are loaded I have an unclosed HTML tag in them. When I replace…
Cipiripi
  • 1,123
  • 5
  • 17
  • 33
26
votes
6 answers

Spring security - creating 403 Access denied custom response

I have a Spring Boot app based on REST api with JWT authentication. The problem is I cannot get rid of default 403 Access Denied rest response which looks like this: { "timestamp": 1516206966541, "status": 403, "error": "Forbidden", …
kubi
  • 897
  • 2
  • 9
  • 23
26
votes
3 answers

What status code should a REST API return for login requests performed with wrong credentials?

I have found a lot of answers and explanations for the meanings of HTTP status codes. My question is specifically about the POST request to a login endpoint, which asks for username and password for example and the scenario where incorrect ones are…
Peter F
  • 3,633
  • 3
  • 33
  • 45
26
votes
1 answer

How to create a response message and add content string to it in ASP.NET 5 / MVC 6

In web api 2 we used to do this to get a response with string content: var response = Request.CreateResponse(HttpStatusCode.Ok); response.Content = new StringContent("", Encoding.UTF8, "application/json"); How can you acheive the…
Sul Aga
  • 6,142
  • 5
  • 25
  • 37
26
votes
3 answers

Some questions about writing on ASP.NET response stream

I'm making tests with ASP.NET HttpHandler for download a file writting directly on the response stream, and I'm not pretty sure about the way I'm doing it. This is a example method, in the future the file could be stored in a BLOB in the database: …
vtortola
  • 34,709
  • 29
  • 161
  • 263
26
votes
8 answers

How do I get the HTTP response status code in AngularJS 1.2

Using ngResource in AngularJS 1.2rc(x), how do I get the status code now? RestAPI.save({resource}, {data}, function( response, responseHeaders ) { }); where RestAPI is my ngResource. The response has the $promise object and the resource returned…
Eddie Monge Jr
  • 12,676
  • 2
  • 19
  • 24