HTTP的GET或POST是否超过?

时间:2013-07-06 22:20:02

标签: apache apache-modules

我正在学习为我正在开发的项目编写Apache模块。我找到了official guide,结果证明非常信息丰富。

在第一页“Developing modules for the Apache HTTP Server 2.4”,“构建处理程序”部分,“request_rec结构”小节提供了一些示例代码:

static int example_handler(request_rec *r)
{
    /* Set the appropriate content type */
    ap_set_content_type(r, "text/html");

    /* Print out the IP address of the client connecting to us: */
    ap_rprintf(r, "<h2>Hello, %s!</h2>", r->useragent_ip);

    /* If we were reached through a GET or a POST request, be happy, else sad. */
    if ( !strcmp(r->method, "POST") || !strcmp(r->method, "GET") ) {
        ap_rputs("You used a GET or a POST method, that makes us happy!<br/>", r);
    }
    else {
        ap_rputs("You did not use POST or GET, that makes us sad :(<br/>", r);
    }

    /* Lastly, if there was a query string, let's print that too! */
    if (r->args) {
        ap_rprintf(r, "Your query string was: %s", r->args);
    }
    return OK;
}

引起我注意的是strcmp上的r->method,看它是POSTGET还是其他。那真是怪了。我认为唯一的HTTP方法是GETPOST?是否有其他东西,或者只是开发人员(或记录员)不必要谨慎?

2 个答案:

答案 0 :(得分:1)

是的,有。

OPTIONS Request options of a Web page
GET     Request to read a Web page
HEAD    Request to read a Web page
PUT     Request to write a Web page
POST    Append to a named resource (e.g. a Web page)
DELETE  Remove the Web page
LINK    Connects two existing resources
UNLINK  Breaks an existing connection between two resources

如需完整参考,请查看HTTP Specification (RFC2616, Chapter 5.1.1)

答案 1 :(得分:1)

定义的常用方法集是RFC2616

  • OPTIONS
  • GET
  • HEAD
  • POST
  • PUT
  • DELETE
  • TRACE
  • CONNECT

但是其他协议使用了许多其他方法。例如,WEBDAV protocol定义了所有这些:

  • PROPFIND
  • PROPPATCH
  • MKCOL
  • COPY
  • MOVE
  • LOCK
  • UNLOCK

有一个draft RFC,其中包含所有已知扩展方法的列表。但是在未来,预计将在HTTP方法注册表中向IANA注册新方法,如here所述。

相关问题