Questions tagged [http]

Hypertext Transfer Protocol (HTTP) is an application level network protocol that is used for the transfer of content on the World Wide Web.

HyperText Transfer Protocol (HTTP) uses a client-request/server-response model. The protocol is stateless, which means it does not require the server to retain information or status about each user for the duration of multiple requests. However, for performance reasons and to avoid the connection-latency issues of TCP, techniques like persistent, parallel or pipelined connections may be used.

The request is sent with an HTTP method:

  • HEAD - used to retrieve the GET response header without the actual content (i.e., just the metadata in the content).
  • GET - used to retrieve data, where the request body is ignored.
  • POST - used to send data, contained in the request body, to the server.

These are all the methods supported by older browsers, but the HTTP 1.1 specification includes a few more: PUT, DELETE, TRACE, OPTIONS, CONNECT and PATCH.

The response is returned with a status code:

  • 1xx are informational
  • 2xx indicates success, most pages will have a 200 status
  • 3xx are used for redirections
  • 4xx codes are used for errors with the request, the commonest being 404 for "Page not found"
  • 5xx are used for server errors

Both the request and response are made up of a header and an optional body.

The header contains a list of key-value pairs, separated using new lines and colons. For example, a request may have headers like this:

Proxy-Connection: keep-alive
Referer: URL
User-Agent: browser name or client application
Accept-Encoding: gzip,deflate
Accept-Language: en-GB

Note that in the example the request is telling the server that the response can be sent with the body compressed with either gzip or DEFLATE encoding.

The request needs a body if it is sending additional data to the server, for instance, if sending information entered into a form.

The response headers will include information telling the client how to deal with the response data, for instance, whether they can cache the data (and how long for).

The response body will have the requested data, such as the HTML of a web page or image data.

HTTP is used by browsers to retrieve web content, but can also be used for data APIs, for instance, as a , , or service.

Versions

Resources

Related Tags

61925 questions
645
votes
14 answers

What is the quickest way to HTTP GET in Python?

What is the quickest way to HTTP GET in Python if I know the content will be a string? I am searching the documentation for a quick one-liner like: contents = url.get("http://example.com/foo/bar") But all I can find using Google are httplib and…
Frank Krueger
  • 64,851
  • 44
  • 155
  • 203
632
votes
12 answers

REST API error return good practices

I'm looking for guidance on good practices when it comes to return errors from a REST API. I'm working on a new API so I can take it any direction right now. My content type is XML at the moment, but I plan to support JSON in future. I am now adding…
Remus Rusanu
  • 273,340
  • 38
  • 408
  • 539
622
votes
7 answers

Are the PUT, DELETE, HEAD, etc methods available in most web browsers?

I've seen a couple questions around here like How to debug RESTful services, which mentions: Unfortunately that same browser won't allow me to test HTTP PUT, DELETE, and to a certain degree even HTTP POST. I've also heard that browsers support…
John Millikin
  • 183,900
  • 37
  • 203
  • 216
601
votes
5 answers

How does HTTP file upload work?

When I submit a simple form like this with a file attached:
Choose a file…
0xSina
  • 18,637
  • 29
  • 125
  • 245
585
votes
24 answers

Error: request entity too large

I'm receiving the following error with express: Error: request entity too large at module.exports (/Users/michaeljames/Documents/Projects/Proj/mean/node_modules/express/node_modules/connect/node_modules/raw-body/index.js:16:15) at json…
mike james
  • 6,780
  • 3
  • 16
  • 20
552
votes
24 answers

Response to preflight request doesn't pass access control check

I'm getting this error using ngResource to call a REST API on Amazon Web Services: XMLHttpRequest cannot load http://server.apiurl.com:8000/s/login?login=facebook. Response to preflight request doesn't pass access control check:…
Andre Mendes
  • 5,807
  • 2
  • 12
  • 22
546
votes
13 answers

PHP + curl, HTTP POST sample code?

Can anyone show me how to do a php curl with an HTTP POST? I want to send data like this: username=user1, password=passuser1, gender=1 To www.domain.com I expect the curl to return a response like result=OK. Are there any examples?
mysqllearner
  • 11,983
  • 14
  • 41
  • 43
523
votes
7 answers

Maximum length of HTTP GET request

What's the maximum length of an HTTP GET request? Is there a response error defined that the server can/should return if it receives a GET request that exceeds this length? This is in the context of a web service API, although it's interesting to…
Mark Harrison
  • 267,774
  • 112
  • 308
  • 434
522
votes
23 answers

Detect when browser receives file download

I have a page that allows the user to download a dynamically-generated file. It takes a long time to generate, so I'd like to show a "waiting" indicator. The problem is, I can't figure out how to detect when the browser has received the file so that…
JW.
  • 47,690
  • 30
  • 108
  • 133
514
votes
7 answers

Share cookie between subdomain and domain

I have two questions. I understand that if I specify the domain as .mydomain.com (with the leading dot) in the cookie that all subdomains can share a cookie. Can subdomain.mydomain.com access a cookie created in mydomain.com (without the www…
adam0101
  • 23,476
  • 18
  • 75
  • 147
509
votes
17 answers

HTTP test server accepting GET/POST requests

I need a live test server that accepts my requests for basic information via HTTP GET and also allows me to POST (even if it's really not doing anything). This is entirely for test purposes. A good example is here. It easily accepts GET requests,…
John Twigg
  • 5,939
  • 3
  • 16
  • 20
508
votes
11 answers

Max parallel http connections in a browser?

I am creating some suspended connections to an HTTP server (comet, reverse ajax, etc). It works ok, but I see the browser only allows two suspended connections to a given domain simultaneously. So if a user is looking at my website in Tab1 of their…
502
votes
8 answers

HTTP POST with URL query parameters -- good idea or not?

I'm designing an API to go over HTTP and I am wondering if using the HTTP POST command, but with URL query parameters only and no request body, is a good way to go. Considerations: "Good Web design" requires non-idempotent actions to be sent via…
Steven Huwig
  • 17,999
  • 8
  • 53
  • 78
498
votes
12 answers

How to redirect to a 404 in Rails?

I'd like to 'fake' a 404 page in Rails. In PHP, I would just send a header with the error code as such: header("HTTP/1.0 404 Not Found"); How is that done with Rails?
Yuval Karmi
  • 24,847
  • 38
  • 116
  • 172
479
votes
14 answers

Why is an OPTIONS request sent and can I disable it?

I am building a web API. I found whenever I use Chrome to POST, GET to my API, there is always an OPTIONS request sent before the real request, which is quite annoying. Currently, I get the server to ignore any OPTIONS requests. Now my question is…
Qian Chen
  • 12,930
  • 14
  • 54
  • 81