Which HTTP method to use for file downloading?

16,461

Solution 1

GET is for passively retrieving files, POST is for altering information on the server. This is as seen from the client, it doesn't matter what the server does or doesn't do in the process.

So unless you're altering some server state in the request: GET.

Solution 2

GET

From http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol

GET Requests a representation of the specified resource. Requests using GET should only retrieve data and should have no other effect. (This is also true of some other HTTP methods.)[1] The W3C has published guidance principles on this distinction, saying, "Web application design should be informed by the above principles, but also by the relevant limitations."[11] See safe methods below.

POST Requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI. The data POSTed might be, as examples, an annotation for existing resources; a message for a bulletin board, newsgroup, mailing list, or comment thread; a block of data that is the result of submitting a web form to a data-handling process; or an item to add to a database.[12]

Share:
16,461
Erik
Author by

Erik

Updated on June 03, 2022

Comments

  • Erik
    Erik almost 2 years

    In my site users can download their files. But files are generated by using PHP. So what's HTTP method should I use for sending request for download as file attachment? GET or POST?

  • Legends
    Legends over 7 years
    What do you mean when you say server state?
  • Gromski
    Gromski over 7 years
    Literally the state the server is in (for anything relevant to the behaviour of the application, excluding incidental stuff like caches or logs). If you alter data in the database, that's a state change.
  • colm.anseo
    colm.anseo almost 3 years
    There are cases where a POST is more desriable - even when the server-states does not change. A GET does not have a request body - a POST can. So if one is sending large data in the request - and URL parameters are not a good fit i.e. 2K limit - then a POST (with its body) may be the only option.