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
5692
votes
35 answers

What is the difference between POST and PUT in HTTP?

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 the Request-URI in the…
alex
  • 67,783
  • 9
  • 46
  • 57
5484
votes
12 answers

The definitive guide to form-based website authentication

Form-based authentication for websites We believe that Stack Overflow should not just be a resource for very specific technical questions, but also for general guidelines on how to solve variations on common problems. "Form based authentication for…
Michiel de Mare
  • 40,513
  • 27
  • 100
  • 132
5157
votes
19 answers

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

What is the maximum length of a URL in different browsers? Does it differ among browsers? Is a maximum URL length part of the HTTP specification?
Sander Versluys
  • 67,197
  • 23
  • 79
  • 89
4568
votes
31 answers

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

People talk about URLs, URIs, and URNs as if they're different things, but they look the same to the naked eye. What are the distinguishable differences between them?
Sean McMains
  • 53,635
  • 12
  • 43
  • 52
4060
votes
35 answers

What exactly is RESTful programming?

What exactly is RESTful programming?
hasen
  • 148,751
  • 62
  • 182
  • 223
2438
votes
21 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
  • 75,014
  • 17
  • 95
  • 156
2006
votes
11 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
  • 992,635
  • 352
  • 3,478
  • 3,452
1680
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
  • 23,831
  • 8
  • 52
  • 64
1574
votes
8 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
  • 34,128
  • 20
  • 104
  • 150
1517
votes
9 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
  • 31,091
  • 29
  • 106
  • 160
1436
votes
6 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
  • 26,552
  • 10
  • 48
  • 72
1325
votes
33 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
  • 13,440
  • 3
  • 11
  • 10
1284
votes
11 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,066
  • 3
  • 11
  • 12
1228
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
  • 26,486
  • 19
  • 63
  • 91
1150
votes
32 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
  • 11,764
  • 3
  • 15
  • 8
1
2 3
99 100