It is important to note that both HTTP POST and HTTP PUT are types of HTTP request methods.
The internet offers a wide variety of resources hosted on different servers. In order to access these resources, your browser must be able to send a request to the servers and display the resources for you. HTTP stands for Hypertext Transfer Protocol and is the basic format used to structure requests and responses for efficient communication between the client and server.
The client sends an HTTP request to the server, and after the message is internalized, the server sends a response. The response contains information about the status of the request.
There are different HTTP request methods, but each one has a specific purpose. The main HTTP methods are as follows:
For the sake of this shot, we will only discuss the POST and PUT methods.
POST is an HTTP method designed to send loads of data between the client (application) and server (computer). The POST request method inherently requires that a web server accepts the data contained in the body of the request message, most likely to store it.
POST is commonly used when uploading a file or submitting a complete web form. A POST request is usually sent through an HTML form and results in a change on the server.
For POST requests, the values are sent in the “body” of the request. For web forms, they will most likely be submitted with the
multipart / form-data, or
application/json media type.
HTTP POST format must contain HTTP headers followed by an empty string, followed by the request body. POST variables are stored in the body as key-value pairs. With the help of tools like Fiddler, you can view the raw HTTP request and the response payloads being sent. The raw content of an HTTP POST is shown below.
POST /path/script.cgi HTTP/1.1 From: firstname.lastname@example.org User-Agent: HTTPTool/1.1 Content-Type: application/x-www-form-urlencoded Content-Length: 32 home=code&run+flavor=flies
The HTTP PUT request method creates a new resource or replaces the target resource representation with the request payload.
The HTTP PUT request method puts a file or resource at the specified
If the PUT request successfully creates a new resource, the server notifies the user by sending a 201 (Created) response, e.g.,
HTTP/1.1 201 Created Content-Location: /new.html.
If the target resource has the current representation and that representation has been successfully changed according to the state of the enclosed representation, the origin server sends a 200 (OK) or 204 (No content) response to indicate that the request was fulfilled, e.g.,
HTTP/1.1 204 No Content Content-Location: /existing.html.
HTTP PUT is paradoxically idempotent. HTTP PUT responses are not cacheable. Below is an example of raw content of an HTTP PUT request:
PUT /new.html HTTP/1.1 Host: example.com Content-type: text/html Content-length: 16 <p>New File</p>
View all Courses