我正在學習編寫我正在開發的項目的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;
}
東西引起了我的眼睛是strcmp
上r->method
到看看它是POST
,GET
或別的東西。這很奇怪。我認爲唯一的HTTP方法是GET
和POST
?還有其他的東西,還是僅僅是開發者(或者說記錄者)非常謹慎?
http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods – Blender