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
397
votes
16 answers

Can PHP cURL retrieve response headers AND body in a single request?

Is there any way to get both headers and body for a cURL request using PHP? I found that this option: curl_setopt($ch, CURLOPT_HEADER, true); is going to return the body plus headers, but then I need to parse it to get the body. Is there any way to…
gremo
  • 47,186
  • 75
  • 257
  • 421
393
votes
11 answers

Response Content type as CSV

I need to send a CSV file in HTTP response. How can I set the output response as CSV format? This is not working: Response.ContentType = "application/CSV";
balaweblog
  • 14,982
  • 28
  • 73
  • 95
391
votes
24 answers

HTTP URL Address Encoding in Java

My Java standalone application gets a URL (which points to a file) from the user and I need to hit it and download it. The problem I am facing is that I am not able to encode the HTTP URL address properly... Example: URL: …
suDocker
  • 8,504
  • 6
  • 26
  • 26
390
votes
3 answers

What is the "realm" in basic authentication

I'm setting up basic authentication on a php site and found this page on the php manual showing the set up. What does "realm" mean here in the header? header('WWW-Authenticate: Basic realm="My Realm"'); Is it the page page being requested?
RayLoveless
  • 19,880
  • 21
  • 76
  • 94
388
votes
22 answers

HTTP vs HTTPS performance

Are there any major differences in performance between http and https? I seem to recall reading that HTTPS can be a fifth as fast as HTTP. Is this valid with the current generation webservers/browsers? If so, are there any whitepapers to support…
Jim Geurts
  • 20,189
  • 23
  • 95
  • 116
385
votes
12 answers

Download File to server from URL

Well, this one seems quite simple, and it is. All you have to do to download a file to your server is: file_put_contents("Tmpfile.zip", file_get_contents("http://someurl/file.zip")); Only there is one problem. What if you have a large file, like…
xaav
  • 7,876
  • 9
  • 30
  • 47
383
votes
6 answers

Send request to cURL with post data sourced from a file

I need to make a POST request via cURL from the command line. Data for this request is located in a file. I know that via PUT this could be done with the --upload-file option. curl host:port/post-file -H "Content-Type: text/xml" --data…
user253202
379
votes
10 answers

400 BAD request HTTP error code meaning?

I have a JSON request which I'm posting to a HTTP URL. Should this be treated as 400 where requestedResource field exists but "Roman" is an invalid value for this field? [{requestedResource:"Roman"}] Should this be treated as 400 where "blah"…
Phoenix
  • 8,695
  • 16
  • 55
  • 88
376
votes
21 answers

What is the fastest way to send 100,000 HTTP requests in Python?

I am opening a file which has 100,000 URL's. I need to send an HTTP request to each URL and print the status code. I am using Python 2.6, and so far looked at the many confusing ways Python implements threading/concurrency. I have even looked at…
IgorGanapolsky
  • 26,189
  • 23
  • 116
  • 147
373
votes
3 answers

How to define the basic HTTP authentication using cURL correctly?

I'm learning Apigility (Apigility docu -> REST Service Tutorial) and trying to send a POST request with basic authentication via cURL: $ curl -X POST -i -H "Content-Type: application/hal+json" -H "Authorization: Basic YXBpdXNlcjphcGlwd2Q="…
automatix
  • 14,018
  • 26
  • 105
  • 230
372
votes
8 answers

ETag vs Header Expires

I've looked around but haven't been able to figure out if I should use both an ETag and an Expires Header or one or the other. What I'm trying to do is make sure that my flash files (and other images and what not only get updated when there is a…
GeoffreyF67
  • 11,061
  • 11
  • 46
  • 56
371
votes
16 answers

HTTP headers in Websockets client API

Looks like it's easy to add custom HTTP headers to your websocket client with any HTTP header client which supports this, but I can't find how to do it with the web platform's WebSocket API. Anyone has a clue on how to achieve it? var ws = new…
Julien Genestoux
  • 31,046
  • 20
  • 66
  • 93
365
votes
35 answers

Node.js EACCES error when listening on most ports

I'm testing out an app (hopefully to run on heroku, but am having issues locally as well). It's giving me an EACCES error when it runs http.Server.listen() - but it only occurs on some ports. So, locally I'm running: joe@joebuntu:~$ node > var h =…
jwegner
  • 7,043
  • 8
  • 34
  • 56
359
votes
12 answers

Sending HTTP POST Request In Java

lets assume this URL... http://www.example.com/page.php?id=10 (Here id needs to be sent in a POST request) I want to send the id = 10 to the server's page.php, which accepts it in a POST method. How can i do this from within Java? I…
Jazz
  • 3,691
  • 4
  • 17
  • 6
353
votes
14 answers

How to prevent an HTTP request just for a favicon?

Everybody knows how to set up a favicon.ico link in their HTML: But it's silly that for only a several-byte-tiny icon we need yet yet another potentially speed-penalizing…
Sam
  • 15,254
  • 25
  • 90
  • 145