2013-07-06 76 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