zoukankan      html  css  js  c++  java
  • http,get,head,post

    http://www.tutorialspoint.com/http/http_methods.htm


    The set of common methods for HTTP/1.0 is defined below. Although this set can be expanded.

    The GET Method

    The GET method means retrieve whatever information (in the form of an entity) is identified by the Request-URI. If the Request-URI refers to a data-producing process, it is the produced data which shall be returned as the entity in the response and not the source text of the process, unless that text happens to be the output of the process.

    A conditional GET method requests that the identified resource be transferred only if it has been modified since the date given by the If-Modified-Since header. The conditional GET method is intended to reduce network usage by allowing cached entities to be refreshed without requiring multiple requests or transferring unnecessary data.

    The GET method can also be used to submit forms. The form data is URL-encoded and appended to the request URI

    The HEAD Method

    A HEAD request is just like a GET request, except it asks the server to return the response headers only, and not the actual resource (i.e. no message body). This is useful to check characteristics of a resource without actually downloading it, thus saving bandwidth. Use HEAD when you don't actually need a file's contents.

    The response to a HEAD request must never contain a message body, just the status line and headers.

    The POST Method

    A POST request is used to send data to the server to be processed in some way, like by a CGI script. A POST request is different from a GET request in the following ways:

    • There's a block of data sent with the request, in the message body. There are usually extra headers to describe this message body, like Content-Type: and Content-Length:

    • The request URI is not a resource to retrieve; it's usually a program to handle the data you're sending.

    • The HTTP response is normally program output, not a static file.

    The most common use of POST, by far, is to submit HTML form data to CGI scripts. In this case, the Content-Type: header is usually application/x-www-form-urlencoded, and the Content-Length: header gives the length of the URL-encoded form data. The CGI script receives the message body through STDIN, and decodes it. Here's a typical form submission, using POST:

    POST /path/script.cgi HTTP/1.0
    From: frog@jmarshall.com
    User-Agent: HTTPTool/1.0
    Content-Type: application/x-www-form-urlencoded
    Content-Length: 32
    
    home=Mosby&favorite+flavor=flies
    

    GET vs POST Methods

    If you were writing a CGI script directly i.e. not using PHP, but Perl, Shell, C, or antoher language you would have to pay attention to where you get the user's value/variable combinations. In the case of GET you would use the QUERY_STRING environment variable and in the case of POST you would use the CONTENT_LENGTH environment variable to control your iteration as you parsed for special characters to extract a variable and its value.

    POST Method:

    • Query length can be unlimited (unlike in GET)

    • Is used to send a chunk of data to the server to be processed.

    • You can send entire files using post.

    • Your form data is attached to the end of the POST request (as opposed to the URL).

    • Not as quick and easy as using GET, but more versatile (provided that you are writing the CGI directly).

    GET Method :

    • Your entire form submission can be encapsulated in one URL, like a hyperlink so can store a query by a just a URL

    • You can access the CGI program with a query without using a form.

    • Fully includes it in the URL: http://myhost.com/mypath/myscript.cgi?name1=value1&name2=value2.

    • Is how your browser downloads most files.

    • Don't use GET if you want to log each request.

    • Is used to get a file or other resource.

  • 相关阅读:
    MySQL+Toad for Mysql安装,配置及导入中文数据解决乱码等问题
    Excel日期格式提取year
    arcgis中使用excel中x,y坐标创建点问题
    GIS中栅格数据的拼接
    R 中安装xlsx包缺少java环境解决方案
    R中统计量的中英文解释
    arcgis离海距离的计算
    EXCEL处理数据小技巧
    nginx部署成功却没有办法访问
    Linux安装yum install gcc-c++出错:Could not retrieve mirrorlist http://mirrorlist.centos.org/?release=7&arch=x86_64&repo=os&infra=stock error was 14: curl#6
  • 原文地址:https://www.cnblogs.com/threef/p/3288504.html
Copyright © 2011-2022 走看看