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

67879 questions
6265
votes
42 answers

What is the difference between POST and PUT in HTTP?

Background Information Analysis: According to RFC 2616, § 9.5, POST is used to create a resource: The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by…
alex
  • 74,215
  • 9
  • 49
  • 57
5642
votes
18 answers

What is the maximum length of a URL in different browsers?

What is the maximum length of a URL for each browser? Is a maximum URL length part of the HTTP specification?
Sander Versluys
  • 72,737
  • 23
  • 84
  • 91
5518
votes
11 answers

The definitive guide to form-based website authentication

Moderator note: This question is not a good fit for our question and answer format with the topicality rules which currently apply for Stack Overflow. We normally use a "historical lock" for such questions where the content still has value.…
Michiel de Mare
  • 41,982
  • 29
  • 103
  • 134
4912
votes
31 answers

What is the difference between a URI, a URL, and a URN?

What is the difference between a URL, a URI, and a URN?
Sean McMains
  • 57,907
  • 13
  • 47
  • 54
4170
votes
35 answers

What exactly is RESTful programming?

What exactly is RESTful programming?
hasen
  • 161,647
  • 65
  • 194
  • 231
3022
votes
24 answers

HTTP GET with request body

I'm developing a new RESTful webservice for our application. When doing a GET on certain entities, clients can request the contents of the entity. If they want to add some parameters (for example sorting a list) they can add these parameters in the…
Evert
  • 93,428
  • 18
  • 118
  • 189
2122
votes
12 answers

How to use java.net.URLConnection to fire and handle HTTP requests

Use of java.net.URLConnection is asked about pretty often here, and the Oracle tutorial is too concise about it. That tutorial basically only shows how to fire a GET request and read the response. It doesn't explain anywhere how to use it to, among…
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
1870
votes
29 answers

How do we control web page caching, across all browsers?

Our investigations have shown us that not all browsers respect the HTTP cache directives in a uniform manner. For security reasons we do not want certain pages in our application to be cached, ever, by the web browser. This must work for at least…
Edward Wilde
  • 25,967
  • 8
  • 55
  • 64
1785
votes
10 answers

HTTP status code for update and delete?

What status code should I set for UPDATE (PUT) and DELETE (e.g. product successfully updated)?
xpepermint
  • 35,055
  • 30
  • 109
  • 163
1716
votes
10 answers

How are parameters sent in an HTTP POST request?

In an HTTP GET request, parameters are sent as a query string: http://example.com/page?parameter=value&also=another In an HTTP POST request, the parameters are not sent along with the URI. Where are the values? In the request header? In the request…
Camilo Martin
  • 37,236
  • 20
  • 111
  • 154
1663
votes
37 answers

Android 8: Cleartext HTTP traffic not permitted

I had reports from users with Android 8 that my app (that uses back-end feed) does not show content. After investigation I found following Exception happening on Android 8: 08-29 12:03:11.246 11285-11285/ E/: [12:03:11.245, main]: Exception:…
david.s
  • 16,880
  • 3
  • 13
  • 11
1625
votes
7 answers

application/x-www-form-urlencoded or multipart/form-data?

In HTTP there are two ways to POST data: application/x-www-form-urlencoded and multipart/form-data. I understand that most browsers are only able to upload files if multipart/form-data is used. Is there any additional guidance when to use one of the…
max
  • 29,122
  • 12
  • 52
  • 79
1507
votes
6 answers

Custom HTTP headers : naming conventions

Several of our users have asked us to include data relative to their account in the HTTP headers of requests we send them, or even responses they get from our API. What is the general convention to add custom HTTP headers, in terms of naming,…
Julien Genestoux
  • 31,046
  • 20
  • 66
  • 93
1347
votes
35 answers

Access-Control-Allow-Origin Multiple Origin Domains?

Is there a way to allow multiple cross-domains using the Access-Control-Allow-Origin header? I'm aware of the *, but it is too open. I really want to allow just a couple domains. As an example, something like this: Access-Control-Allow-Origin:…
Thomas J Bradley
  • 13,726
  • 3
  • 18
  • 8
1345
votes
14 answers

SOAP vs REST (differences)

I have read articles about the differences between SOAP and REST as a web service communication protocol, but I think that the biggest advantages for REST over SOAP are: REST is more dynamic, no need to create and update UDDI(Universal…
Abdulaziz
  • 13,694
  • 3
  • 13
  • 12
1
2 3
99 100