All data within the Web technology is transmitted via the protocol HTTP. The exception is exchange using Java programming or exchange from Plugin applications. Considering the actual volume of traffic that is transmitted as part of a Web exchange over HTTP, we will only consider this protocol. In doing so, we will focus on issues such as:

  • general message structure;
  • access methods;
  • optimization of exchanges.

General message structure

HTTP is an application layer protocol. It is focused on the client-server exchange model. The client and server exchange pieces of data called HTTP messages. Messages sent by a client to a server are called requests, and messages sent by a server to a client are called responses. A message can consist of two parts: a header and a body. The body is separated from the header by a blank line.

The header contains service information necessary to process the message body or control the exchange. The header consists of header directives, which are usually written each on a new line.

The message body is optional, but the message header is. It may contain text, graphics, audio or video information.

Below is the HTTP request:

GET / HTTP/1.0 Accept: image/jpeg empty string

And the response:

HTTP/1.0 200 OK Date: Fri, 24 Jul 1998 21:30:51 GMT Server: Apache/1.2.5 Content-type: text/html Content-length: 21345 empty string ...

The text "empty line" is simply to indicate the presence of an empty line that separates the header of an HTTP message from its body.

The server, receiving a request from a client, converts part of the HTTP request header information into environment variables, which are available for analysis by a CGI script. If the request has a body, then it becomes available to the script via the standard input stream.

Access Methods

The most important directive of an HTTP request is the access method. It is indicated as the first word in the first line of the query. In our example this is GET. There are four main access methods:

  • HEAD;
  • POST;

In addition to these four methods, there are about five additional access methods, but they are rarely used.

GET method

The GET method is used by the client when making a request to the server by default. In this case, the client reports the resource address (URL) that it wants to receive, the HTTP protocol version, the MIME document types it supports, the version and name of the client software. All these parameters are specified in the HTTP request header. The body is not sent in the request.

In response, the server reports the HTTP protocol version, return code, message body content type, message body size, and a number of other optional HTTP header directives. The resource itself, usually an HTML page, is sent in the body of the response.

HEAD method

The HEAD method is used to reduce exchanges when working over the HTTP protocol. It is similar to the GET method except that the message body is not sent in the response. This method used to check the last modification time of a resource and the expiration date of cached resources, as well as when using World resource scanning programs Wide Web. In short, the HEAD method is designed to reduce the amount of information transmitted over the network as part of an HTTP exchange.

POST method

The POST method is an alternative to the GET method. When exchanging data using the POST method, the client request contains an HTTP message body. This body can be formed from data that is entered in an HTML form, or from an appended external file. The response typically contains both a header and a body of the HTTP message. To initiate an exchange using the POST method, the METHOD attribute of the FORM container must be set to "post".

PUT method

The PUT method is used to publish HTML pages to the HTTP server directory. When transmitting data from a client to a server, the message contains both a message header, which indicates the URL of the resource, and a body - the content of the hosted resource.

The response usually does not send the resource body, but rather the message header contains a return code that determines whether the resource allocation was successful or unsuccessful.

Optimization of exchanges

The HTTP protocol was not originally designed for permanent connection. This means that once the server has accepted a request from the client and responded to it, the connection between the client and the server is broken. For new data exchange, a new connection must be established. This approach has both advantages and disadvantages.

The advantages include the ability to simultaneously service a large number of short requests. Even on popular servers, the number of open connections may not exceed hundreds when servicing about a million requests per day. Moreover, one client can open up to 40 connections at the same time, and from the server’s point of view they are all equal. With high-speed communication lines, this makes it possible to achieve a short response time to a client request for the entire page (text, graphics, etc.).

The disadvantages of this exchange scheme include: the need to establish a connection each time and the inability to maintain a session with information resource. When initializing a connection via the TCP transport protocol and terminating this connection, it is necessary to transfer a fairly large amount of service information. The lack of session support in HTTP makes it difficult to work with resources such as databases or resources that require authentication.

To optimize the number of open TCP connections, the HTTP protocol versions 1.0 and 1.1 provide a keep-alive mode. In this mode, the connection is initialized only once, and several HTTP exchanges can be carried out sequentially over it.

To provide session support, cookies have been added to the HTTP header directives. They allow you to simulate connection support when working over the HTTP protocol.

Types of user interface in Web technology

World Wide Web pages can be divided into several types according to their functional purpose: information pages, navigation pages, data exchange pages. In many cases, these functions can be combined into one page.

Information pages are a sequential presentation of information with the possibility of hypertext contextual transitions. The user views them sequentially. Hypertext links are typically used to create footnotes, notes, or references to reference lists and other associated materials. Typical examples of such pages are tips, guides, company descriptions, historical information, etc.

Navigation pages are a collection of hypertext links that allow you to navigate through the materials of a Web site. A typical example of such a page is Home page ( Homepage). As a rule, it does not contain lengthy text descriptions and illustrations; it consists of a collection of different menus. These menus can be implemented through lists, link tables, or imagemaps.

Data exchange pages allow you to transfer to the server a certain amount of information that differs from the standard address (URL) of the resource. When browsing and navigating, the user simply selects hypertext links that load new pages. When exchanging data, not only the resource address is transmitted to the server, but also Additional Information, which is entered by the user.

Depending on the functional purpose pages, the appearance of the resource interface with which the user deals changes. In the first two cases, just use the mouse to select a hypertext link, and it will immediately load new page. In the case of data exchange pages, you must fill out the HTML form fields and send the data to the server.

Moreover, forms provide almost all the necessary types of input fields and menus. The only thing that HTML forms don't allow is nested menus. Forms can be used for more than just data exchange. Quite developed form processing mechanisms are present in JavaScript.

612

HTTP PUT:

PUT places a file or resource at a specific URI, and it is at that URI. If there is already a file or resource in this URI, PUT replaces that file or resource. If there is no file or resource there, PUT creates one. PUT is idempotent, but, paradoxically, PUT responses are not cacheable.

HTTP POST:

POST sends data to a specific URI and waits for a resource at that URI to process the request. The web server at this point can determine what to do with the data in the context of the specified resource. POST method is not idempotent but POST responses are : are cached if the server sets the appropriate Cache-Control and Expires headers.

The official HTTP RFC defines POST to be:

  • Abstract of existing resources;
  • Posting a message to a bulletin board, news group, mailing list, or similar group of articles;
  • Providing a block of data, such as the result of a form submission, to the data processing process;
  • Expanding a database using an append operation.

Difference between POST and PUT:

The RFC itself explains the kernel difference:

The fundamental difference between POST and PUT requests is reflected in the different Request-URI value. The URI in the POST request identifies the resource that will process the enclosed object. This resource could be the process receiving the data, a gateway to another protocol, or a separate entity that receives the annotations. In contrast, the URI in a PUT request identifies the entity included in the request - the user agent knows that the URI is intended and the server SHOULD NOT attempt to apply the request to some other resource. If the server wishes the request to be applied to a different URI, it MUST send a 301 (moved persistent) response; the user agent MAY then make its own decision as to whether to redirect the request or not.

Using the correct method, unrelated aside:

I've been getting quite annoyed lately by a popular misconception among web developers that POST is used to create a resource and PUT is used to update/change.

If you look at page 55 of RFC 2616 ("HyperText Transfer Protocol - HTTP/1.1"), Section 9.6 ("PUT"), you will see that PUT is actually for:

The PUT method requests that a private object be stored in the requested Request-URI.

There's also a handy point to explain the difference between POST and PUT:

The fundamental difference between POST and PUT requests is reflected in the different Request-URI value. The URI in the POST request identifies the resource that will process the enclosed object. This resource could be a data acceptance process, a gateway to another protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed by the request - the user agent knows what the URI is, and the server SHOULD NOT attempt to apply the request to another resource.

It doesn't say anything about the update/create distinction, because that's not what it's about. It's about the difference between this:

Obj.set_attribute(value) # A POST request.

Obj.attribute = value # A PUT request.

So please stop spreading this popular misconception. Read your RFCs.

9

It seems useless in a rude and pedantic less useful way. In the PUT example you quote, new object in RESTful, the api is a "new" entry and is available in this location. There is no doubt whether it is a good choice design allowing subspecies to be like this (I think it's not ideal), but even if you were to use subspecies to attack the larger useful information. In most cases, the description is usually said to be an excellent statement of the contents of the RFC, summarized and a statement of common and customary practice. Plus, it won't hurt you to be polite. - tooluser 06 Apr 15 2015-04-06 23:49:56

60

1) GET: - Used when a client requests a resource from a web server.

2) HEAD: - Used when the client requests some information about a resource, but does not request the resource itself.

3) POST: - Used when a client sends information or data to a server, such as by filling out an online form (i.e., sends a large amount of complex data to the web server).

4) PUT: - Used when the client sends a replacement document or downloads new document to the web server under the request URL.

5) DELETE: - Used when the client tries to delete a document from the web server identified by the request URL.

6) TRACE: - Used when a client requests available proxies or intermediate servers modifying the request to advertise itself.

7) OPTIONS: - Used when the client wants to define other available methods for retrieving or processing the document on the web server.

8) CONNECT: - Used when a client wants to establish a transparent connection with a remote host, typically to provide SSL-encrypted communication (HTTPS) through an HTTP proxy.

15

  • DELETE: Deletes data from the server.
  • TRACE: Provides a way to check which server is receiving. It simply returns what was sent.
  • OPTIONS: Allows the client to obtain information about the request methods supported by the service. The corresponding response header is "Allow" with supported methods. Also used in CORS as a pre-flight request to inform the server about the actual request method and ask about custom headers.
  • HEAD: Returns response headers only.
  • CONNECT: Used by the browser when it knows it is talking to a proxy and the final URI starts with https://. The purpose of CONNECT is to allow an end-to-end encrypted TLS session so the data is unreadable to the proxy.
  • 15 answers

    HTTP PUT:

    PUT places a file or resource at a specific URI and exactly that URI. If there is already a file or resource in this URI, PUT replaces that file or resource. If there is no file or resource there, PUT creates one. PUT is idempotent, but paradoxically PUT responses are not cacheable.

    HTTP POST:

    POST sends data to a specific URI and expects the resource at that URI to process the request. The web server at this point can determine what to do with the data in the context of the specified resource. The POST method is not idempotent, however POST responses can be cached if the server sets the appropriate Cache-Control and Expires headers.

    The official HTTP RFC defines POST as:

    • Abstract of existing resources;
    • Posting a message to a bulletin board, news group, mailing list, or similar group of articles;
    • Providing a block of data, for example the result of a form submission, to the data processing process;
    • Expanding a database using an append operation.

    Difference between POST and PUT:

    The RFC itself explains the main difference:

    The main difference between POST and PUT requests is reflected in the different meaning of the Request-URI. The URI in the POST request identifies the resource that will process the private entity. That resource could be a data receiving process, a gateway for some other protocol, or a separate object that accepts annotations. In contrast, the URI in a PUT request identifies the entity attached to the request - the user agent knows what the URI is and the server SHOULD NOT attempt to apply the request to another resource. If the server wishes the request to be applied to a different URI, it MUST send a 301 (moved persistent) response; the user agent MAY then make its own decision as to whether the request should be redirected.

    Usage correct method, unrelated aside:

    Just semantics.

    HTTP PUT is supposed to accept the request body and then store it on the resource identified by the URI.

    HTTP POST is more general. It is supposed to initiate an action on the server. This action may be to store the request body in the resource identified by the URI, or it may be a different URI, or it may be a different action.

    PUT , For example. Placed in a URI affects that particular URI. POST to a URI may have no effect at all.

    To give examples of REST style resources:

    "POST/books" with a bunch of information about a book can create a new book and respond with a new URL identifying that book: "/books/5".

    "PUT/books/5" will have to either create a new book with ID 5 or replace an existing book with ID 5.

    In non-resource style, POST can be used for almost anything that has a side effect. Another difference is that a PUT must be idempotent - multiple PUTs of the same data for the same URL must be exact if multiple POSTs can create multiple objects or whatever your POST action does.

    1) GET: - Used when a client requests a resource from a web server.

    2) HEAD: - used when the client requests some information about a resource, but does not request the resource itself.

    3) POST: - used when a client sends information or data to a server, for example by filling out an online form (i.e. sends a large amount of complex data to a web server).

    4) PUT: - Used when the client sends a replacement document or uploads a new document to the web server under the request URL.

    5) DELETE: - Used when the client tries to delete a document from the web server specified by the request URL.

    6) TRACE: - Used when the client asks available proxies or intermediate servers to modify the request to advertise itself.

    7) OPTIONS: - Used when the client wants to define other available methods for retrieving or processing the document on the web server.

    8) CONNECT: - Used when a client wants to establish a transparent connection with a remote host, typically to provide SSL encrypted communication (HTTPS) through an HTTP proxy.

    Others have already posted excellent answers, I just wanted to add that with most languages, frameworks and use cases, you will deal with POST much, much more often than PUT. By the time PUT, DELETE, etc. These are mostly trivial questions.

    According to RFC, the difference between PUT and POST is in the request URI. The URI identified by POST specifies the entity that will handle the POST request. The URI in a PUT request includes the object in the request. So POST /v1/coffees/orders means creating a new resource and returning an ID to describe the resource. In contrast, PUT /v1/coffees/orders/1234 means updating the resource identified by "1234", if it exists; otherwise create new order and use the URI orders/1234 to identify it.

    PUT and POST can both be used to create or update methods. The usage of the method depends on the idempotent behavior expected from the method as well as the location of the resource to identify it.

    POST is considered something like a factory method. You incorporate data with it to create what you want, and whatever is on the other end knows what to do with it. PUT is used to update existing data at a given URL, or to create something new when you know there will be a URI and it doesn't exist yet (unlike POST, which will create something and return the URL if necessary ).

    Lately I've been really annoyed by a popular misconception among web developers that POST is used to create a resource and PUT is used to update/change.

    If you look at page 55 of RFC 2616 ("Hypertext Transfer Protocol - HTTP/1.1"), section 9.6 ("PUT"), you will see that PUT is valid for:

    The PUT method requests that a private object be stored in the supplied Request-URI.

    Theres also a handy paragraph to explain the difference between POST and PUT:

    The main difference between POST and PUT requests is reflected in the different Request-URI value. The URI in the POST request identifies the resource that will process the enclosed object. This resource could be a data acceptance process, a gateway to another protocol, or a separate entity that accepts annotations. In contrast, the URI in a PUT request identifies the entity enclosed by the request - the user agent knows what the URI is, and the server SHOULD NOT attempt to apply the request to another resource.

    It doesn't say anything about the update/create distinction, because that's not what it's about. About the difference between this:

    Obj.set_attribute(value) # A POST request.

    Obj.attribute = value # A PUT request.

    So please stop spreading this popular misconception. Read your RFCs.

    REST asks developers to use HTTP methods explicitly and in a way that matches the protocol's definition. This basic REST design principle establishes a one-to-one mapping between create, read, update, and delete (CRUD) operations and HTTP methods. According to this display:

    To create a resource on the server, use POST.

    To get a resource, use GET.

    To change the state of a resource or update it, use PUT.

    To remove or remove a resource, use DELETE.

    HTTP (English HyperText Transfer Protocol - “hypertext transfer protocol”) is an application layer protocol for data transfer (initially in the form of hypertext documents in HTML format). The basis of HTTP is the client-server technology, that is, it assumes the existence of consumers (clients) who initiate a connection and send a request, and providers (servers) who wait for a connection to receive a request, perform the necessary actions and return a message with the result. HTTP is now widely used on the World Wide Web to retrieve information from websites.

    HTTP is also used as a “transport” for other application-level protocols, such as SOAP, XML-RPC, WebDAV.

    The main object of manipulation in HTTP is the resource pointed to by the URI (Uniform Resource Identifier) ​​in the client request. Typically these resources are files stored on the server, but they can be logical objects or something abstract. A feature of the HTTP protocol is the ability to specify in the request and response the method of representing the same resource according to various parameters: format, encoding, language, etc. (In particular, the HTTP header is used for this.) It is thanks to the ability to specify the method of encoding the message that the client and the server can exchange binary data, although this protocol is text.

    HTTP is an application-level protocol, similar to FTP and SMTP. Messages are exchanged according to the usual request-response scheme. HTTP uses global URIs to identify resources. Unlike many other protocols, HTTP is stateless. This means that there is no persistence of intermediate state between request-response pairs. Components using HTTP can independently maintain state information associated with recent requests and responses (for example, “cookies” on the client side, “sessions” on the server side). The browser sending the requests can track response delays. The server can store the IP addresses and request headers of the latest clients. However, the protocol itself is not aware of previous requests and responses, it does not provide internal state support, and no such requirements are imposed on it.

    Advantages

      This protocol is very simple to implement, and is highly extensible by introducing its own headers that add functionality to the application, and which will be ignored by other applications that consider them unknown:

      Simplicity. The protocol is easy to implement, making it easy to create client applications.

      Extensibility. The capabilities of the protocol are easily expanded by introducing your own headers, with the help of which you can obtain the necessary functionality when solving a specific problem. At the same time, compatibility with other clients and servers is maintained: they will simply ignore headers unknown to them.

      Prevalence. When choosing the HTTP protocol to solve specific problems, an important factor is its prevalence. As a consequence, this is an abundance of various documentation on the protocol in many languages ​​​​of the world, the inclusion of easy-to-use development tools in popular IDEs, support for the protocol as a client in many programs, and a wide choice among hosting companies with HTTP servers.

    Protocol structure

    Each HTTP message consists of three parts, which are transmitted in the specified order:

      Starting line - determines the type of message;

      Headers - characterize the body of the message, transmission parameters and other information;

      Message Body - the message data itself. Must be separated from headings by a blank line.

    Headers and body of the message may be missing, but the start line is a required element as it indicates the type of request/response. An exception is version 0.9 of the protocol, in which the request message contains only the start line, and the response message contains only the body of the message.

    Start line

    The starting lines are different for the request and response. The query string looks like this:

    GET URI - for protocol version 0.9.

    HTTP URI/Version method - for other versions.

      Method - name of the request, one word in capital letters. In HTTP 0.9, only the GET method was used; the list of requests for version 1.1 is presented below.

      The URI specifies the path to the requested document.

      Version - a pair of numbers separated by a dot. For example: 1.0

    The starting line of the server response has the following format: HTTP/VersionState Code Explanation, Where:

      Version - a pair of numbers separated by a dot, as in the request.

      Status Code - three digits. The status code determines the further contents of the message and the client's behavior.

      Explanation (English Reason Phrase) - a short text explanation of the response code for the user. Does not affect the message in any way and is optional.

    For example, the starting line of the server's response to the previous request might look like this:

    Methods

    HTTP Method - a sequence of any characters, except for controls and separators, indicating the main operation on a resource. Typically the method is a short English word written in capital letters. Please note that the method name is case sensitive.

    Every server must support at least the GET and HEAD methods. If the server does not recognize the method specified by the client, it should return status 501 (Not Implemented). If the server knows the method, but it is not applicable to a specific resource, then a message with code 405 (Method Not Allowed) is returned. In both cases, the server SHOULD include an Allow header in the response message with a list of supported methods.

    In addition to the GET and HEAD methods, the POST method is often used.

    OPTIONS Used to determine web server capabilities or connection parameters for a specific resource. The server SHOULD include an Allow header in its response with a list of supported methods. The response header may also include information about supported extensions.

    It is expected that the client's request may contain a message body to indicate the information it is interested in. Body format and procedure for working with it currently indefined. The server should ignore it for now. The situation is similar with the body in the server response.

    In order to find out the capabilities of the entire server, the client must specify an asterisk - “*” in the URI. OPTIONS * HTTP/1.1 requests can also be used to check the health of the server (similar to pinging) and to test whether the server supports HTTP version 1.1.

    The result of this method is not cached.

    Used to query the contents of a specified resource. You can also start a process using the GET method. In this case, information about the progress of the process should be included in the body of the response message.

    The client can pass request execution parameters in the URI of the target resource after the "?" character:

    GET /path/resource?param1=value1¶m2=value2 HTTP/1.1

    Similar to the GET method, except that there is no body in the server response. The HEAD request is typically used to retrieve metadata, check the existence of a resource (URL validation), and see if it has changed since it was last accessed.

    Response headers may be cached. If a resource's metadata does not match the corresponding information in the cache, the copy of the resource is marked as out of date.

    Used to transfer user data to a specified resource. For example, on blogs, visitors can typically enter comments on posts into an HTML form, after which they are POSTed to the server and placed on the page. In this case, the transmitted data (in the example with blogs, the text of the comment) is included in the body of the request. Similarly, using the POST method, files are usually uploaded to the server.

    Unlike the GET method, the POST method is not considered idempotent, meaning that repeating the same POST requests over and over again may return different results (for example, after each comment is submitted, another copy of that comment will appear).

    If the execution result is 200 (Ok), a message about the completion of the request should be included in the response body. If a resource has been created, the server SHOULD return a 201 (Created) response with the URI of the new resource in the Location header.

    The server response message to the POST method is not cached.

    Used to load the request content to the URI specified in the request. If a resource does not exist at the given URI, the server creates it and returns status 201 (Created). If the resource has been changed, the server returns 200 (Ok) or 204 (No Content). The server MUST NOT ignore invalid Content-* headers sent by the client along with the message. If any of these headers cannot be recognized or are not valid under current conditions, then an error code of 501 (Not Implemented) must be returned.

    The fundamental difference between the POST and PUT methods is the understanding of the purpose of the resource URI. The POST method assumes that the specified URI will process the content sent by the client. By using PUT, the client assumes that the content being downloaded matches the resource located at the given URI.

    Server response messages to the PUT method are not cached.

    Similar to PUT, but applies only to a fragment of the resource.

    Deletes the specified resource.

    Returns the received request so that the client can see what information intermediate servers add or change in the request.

    Establishes a connection between the specified resource and others.

    Removes the connection of the specified resource with others.

    Converts a request connection into a transparent TCP/IP tunnel, typically to facilitate the establishment of a secure SSL connection through an unencrypted proxy.

    PHP provides support for the HTTP PUT method used by some clients to store files on a server. PUT requests are much simpler than a file upload using POST requests and they look something like this:

    PUT /path/filename.html HTTP/1.1

    This would normally mean that the remote client would like to save the content that follows as: /path/filename.html in your web tree. It is obviously not a good idea for Apache or PHP to automatically let everyone overwrite any files in your web tree. So, to handle such a request you have to first tell your web server that you want a certain PHP script to handle the request. In Apache you do this with the Script directive. It can be placed almost anywhere in your Apache configuration file. A common place is inside a block or perhaps inside a block. A line like this would do the trick:

    Script PUT /put.php

    This tells Apache to send all PUT requests for URIs that match the context in which you put this line to the put.php script. This assumes, of course, that you have PHP enabled for the .php extension and PHP is active. The destination resource for all PUT requests to this script has to be the script itself, not a filename the uploaded file should have.

    With PHP you would then do something like the following in your put.php. This would copy the contents of the uploaded file to the file myputfile.ext on the server. You would probably want to perform some checks and/or authenticate the user before performing this file copy.

    Example #1 Saving HTTP PUT files

    /* PUT data comes in on the stdin stream */
    $putdata = fopen("php://input" , "r" );

    /* Open a file for writing */
    $fp = fopen("myputfile.ext" , "w" );

    /* Read the data 1 KB at a time
    and write to the file */
    while ($data = fread ($putdata, 1024))
    fwrite ($fp, $data);

    /* Close the streams */
    fclose($fp);
    fclose($putdata);
    ?>

    13 years ago

    A Case Study: To set up publishing with Netscape 7.2 Composer to Apache/PHP, no need to use CGI (which I tried unsuccessfully for too long) or to alter Apache"s httpd.conf. I needed only to click Publish As, fill in put2disk.php as the filename (where its contents are the below), and fill in that file"s dir as the "Publishing address".
    XAMPP 1.4.14: Apache/2.0.54 (Win32) mod_ssl/2.0.54 OpenSSL/0.9.7g PHP/5.0.4.

    //file_put_contents("get_def.out", print_r(get_defined_vars(), TRUE)); //debugging

    // Two slurp methods: (a) didn't work, (b) did.
    //$stdin_rsc = fopen("php://input", "r");
    //$putdata="";
    //while ($putdata .= fread($stdin_rsc, 1024)); // a. Hangs the "Publishing..." dialog.
    //while (!feof($stdin_rsc)) $putdata.=fread($stdin_rsc, 8192); // b. Worked, but file_get_contents is faster.
    //fclose($stdin_rsc);

    // All that's nec:
    $putdata=file_get_contents("php://input"); // Not php://stdin! (When the ability to see error messages isn't available, the doc (this manual page) needs to be more accurate.)

    file_put_contents("stdin.out",$putdata);
    ?>