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
26
votes
7 answers

How to access POST data in PHP?

I need to write a PHP page which would accept an XML document sent over a POST request like this: POST /mypage.php HTTP/1.1 Host: myhost.com Content-Type: application/xml Content-Length: ...
peter
26
votes
5 answers

Should deleting a non-existent resource result in a 404 in RESTful Rails?

In a brand new Rails application with a scaffolded RESTful model, the generated delete code looks like this: class BeersController < ApplicationController # DELETE /beers/1 # DELETE /beers/1.xml def destroy @beer = Beer.find(params[:id]) …
Brad
  • 937
  • 1
  • 9
  • 23
26
votes
17 answers

How to fix Invalid request (Unsupported SSL request)

I'm setting up my laravel application and every time I run php artisan serve, it starts a laravel development serve at localhost:8000. Bu when i open the locahost link on the browser, it forces the http to https and logs invalid request (unsupported…
zaghadon
  • 613
  • 1
  • 7
  • 20
26
votes
10 answers

Facebook login on localhost - connection not secure

I am adding a Facebook login to our React project, using Facebook Javascript SDK. I followed this tutorial. When I click the login button which I added to the page, following error is shown: Facebook has detected X isn't using a secure connection to…
druskacik
  • 2,176
  • 2
  • 13
  • 26
26
votes
2 answers

Python Requests HTTP Response 406

I have my own domain where an json file is stored (http://example.com/file.json). When accesing the file in browser using the direct link, the json is returned just fine. But when using the same approach in my python code below, the http response is…
DNac
  • 2,663
  • 8
  • 31
  • 54
26
votes
6 answers

How to post form-data IFormFile with HttpClient?

I have backend endpoint Task Post(IFormFile csvFile) and I need to call this endpoint from HttpClient. Currently I am getting Unsupported media type error. Here is my code: var filePath = Path.Combine("IntegrationTests",…
Deivydas Voroneckis
  • 1,973
  • 3
  • 19
  • 40
26
votes
4 answers

java 11 HttpClient leads to endless SSL loop

I am using the new java.net.http.HttpClient with the sendAsync method. The HttpClient is inside a Singelton and is created once like so: HttpClient.newBuilder().build() so really nothing special. Those requests can be POST or GET but I don't know…
Zarathustra
  • 2,853
  • 4
  • 33
  • 62
26
votes
2 answers

Chrome issue - video stream & session conflict

I have a problem with the implementation of videos in javascript and PHP. index.php session_start() // do other stuff include ‘video.php’ video.php
akio
  • 851
  • 9
  • 29
26
votes
5 answers

Vue.js - Which component lifecycle should be used for fetching data?

After reading one of Alligator.io posts about Vue that was saying that mounted lifecycle is a bad place to use http get. I was wondering if there are any guidelines to how properly get data from API in Vue.js?
kkot
  • 477
  • 2
  • 6
  • 13
26
votes
3 answers

Curl: Error: (3) Port number ended with '"'

I am trying to get a token of a dot net core 2.0 web api. This is what I am doing: C:\Users\danyb>curl -X POST -H 'Content-Type:application/json'^ Mehr? -d '{\"username\":\"mario\",\"password\":\"secret\"}'^ Mehr? localhost:56183/api/token [1/2]:…
BlockchainProgrammer
  • 1,999
  • 5
  • 20
  • 32
26
votes
1 answer

Angular Set HTTP Timeout

I was looking for a way to stop/terminate an http request if it exceeds a certain time. So in Angular 5, is there anyway to set a timeout for an http request? If there is a way, how can we do something, like execute some function, after a timeout?…
S K
  • 453
  • 1
  • 6
  • 13
26
votes
3 answers

Should cookie values be URL encoded?

When setting cookies, PHP url-encodes the cookie value (at least when not using setrawcookie) and it url-decodes the cookie value before making it available to the application in $_COOKIE. Is this an accepted standard? If I set a raw cookie value of…
AndreKR
  • 32,613
  • 18
  • 106
  • 168
26
votes
3 answers

How to modify the header of a HttpUrlConnection

Im trying to improve the Java Html Document a little but i'm running into problems with the HttpUrlConntion. One thing is that some servers block a request if the user agent is a Java VM. Another problem is that the HttpUrlConnection does not set…
tigger
  • 1,856
  • 3
  • 18
  • 23
26
votes
4 answers

Other common protocols besides HTTP?

I usually pass data between my web servers (in different locations) using HTTP requests (sometimes using SSL if it's sensitive). I was wondering if there were any lighter protocols that I might be able to swap HTTP(S) for that would also support…
Xeoncross
  • 55,620
  • 80
  • 262
  • 364
26
votes
5 answers

How do I do awesome refreshless page changes like GitHub do?

GitHub seems to be doing something incredible: animated page changes without breaking state. The address bar changes, but the page doesn't refresh and I get animated to the next view. For example, hit this URL: as3logback/ then hit this URL:…
Naftuli Kay
  • 87,710
  • 93
  • 269
  • 411