2013-07-06 36 views
0

我正在学习编写我正在开发的项目的Apache模块。我发现official guide,原来是资料。HTTP是否有GET或POST?

在第一页上,“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; 
} 

东西引起了我的眼睛是strcmpr->method到看看它是POST,GET别的东西。这很奇怪。我认为唯一的HTTP方法是GETPOST?还有其他的东西,还是仅仅是开发者(或者说记录者)非常谨慎?

+0

http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods – Blender

回答

1

该组的常见的方法被定义为RFC2616

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

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

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

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

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)

+0

您是否告诉我可以使用HTTP删除随机网页? –

+0

@ColeJohnson就像你不能POST任何随机的网址,你不能删除任何随机的网址。但是,如果服务器也选择了某种资源,它可以支持该方法。通常情况下,这需要某种授权。 –

+0

@ColeJohnson这些动词主要用于REST应用程序。在那里你可以从服务器中删除一个明确标识的对象(假设你有权这样做)。 – Camouflage