HTTP - PUT 上传文件/Shell
今天遇到幾個PUT上傳的點,但是都沒利用起來。一怒之下,在自己本地試了一下。步驟如下:
一、環(huán)境:
首先,根據(jù)?配置Apache服務(wù)器支持向目錄PUT文件?更新一下httpd.conf文件,重啟所有服務(wù)。
二、HTTP - PUT
PUT的前提,是了解HTTP協(xié)議。下面給出HTTP - PUT的一個模板:
PUT /test.txt HTTP/1.1 Accept: */* Accept-Language: en-US User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Win32) Host: test.com:8080hello world要注意如下幾個點:
① PUT方法是HTTP 1.1協(xié)議中才出現(xiàn)的。
② HTTP協(xié)議對空格敏感,每行數(shù)據(jù)的結(jié)尾不能出現(xiàn)空格
③ HTTP頭部和數(shù)據(jù)中間要空一行,即HTTP頭部是以\r\n\r\n結(jié)尾的。
④ 端口號直接跟在HOST后面
三、第一次PUT
好了,現(xiàn)在可以PUT了。用Linux下的nc命令來進行連接。
nc -v www.baidu.com 80 root@bb:/etc# nc -v 192.168.163.1 8080 nc: 192.168.163.1 (192.168.163.1) 8080 [http-alt] open/*在得到如上輸出之后,再將PUT包的內(nèi)容貼到命令行中,回車*/ PUT /test.txt HTTP/1.1 Content-Length: 11 Accept-Language: en-US User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Win32) Host: 192.168.163.1:8080hello world
/*發(fā)送的PUT包到此為止,以下為收到的數(shù)據(jù)包*/ HTTP/1.1 500 Internal Server Error Date: Wed, 29 Apr 2015 09:15:18 GMT Server: Apache/2.2.21 (Win64) PHP/5.3.10 DAV/2 Content-Length: 535 Connection: close Content-Type: text/html; charset=iso-8859-1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>500 Internal Server Error</title> </head><body> <h1>Internal Server Error</h1> <p>The server encountered an internal error or misconfiguration and was unable to complete your request.</p> <p>Please contact the server administrator, admin@localhost and inform them of the time the error occurred,and anything you might have done that may have caused the error.</p> <p>More information about this error may be available in the server error log.</p> </body></html>
好像不對啊,500是服務(wù)器內(nèi)部錯誤啊。好吧好吧,我們?nèi)タ纯粗鳈C的Apache日志。
四、再次配環(huán)境
主機用的是WAMP,日志在/wamp/logs/apache_error.log。找到對應(yīng)的那一條:
?
通過瀏覽器搜索,又找到一篇日志。Linux(CentOS) 服務(wù)端搭建與配置,原來用HTTP - PUT還要添加一個什么鎖。
所以解決方法是:在Apache配置文件中,也就是httpd.conf,增加一行,設(shè)定webDAV鎖位置。再次重啟所有服務(wù)。 DavLockDB DavLock #目錄沒有就創(chuàng)建(DavLock 為文件名,應(yīng)該有的目錄結(jié)構(gòu)是\wamp\bin\apache\Apache2.2.21\DavLock) 五、終于成功PUT root@bb:/etc# nc -v 192.168.163.1 8080 nc: 192.168.163.1 (192.168.163.1) 8080 [http-alt] open PUT /test.txt HTTP/1.1 Content-Length: 11 Accept-Language: en-US User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Win32) Host: 192.168.163.1:8080hello world HTTP/1.1 201 Created Date: Wed, 29 Apr 2015 09:25:24 GMT Server: Apache/2.2.21 (Win64) PHP/5.3.10 DAV/2 Location: http://192.168.163.1:8080/test.txt Content-Length: 181 Content-Type: text/html; charset=ISO-8859-1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>201 Created</title> </head><body> <h1>Created</h1> <p>Resource /test.txt has been created.</p> </body></html>0。0 差不多這樣,之后有更多關(guān)于PUT的經(jīng)驗,再分享
?
轉(zhuǎn)載于:https://www.cnblogs.com/kuoaidebb/p/4466602.html
總結(jié)
以上是生活随笔為你收集整理的HTTP - PUT 上传文件/Shell的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: NOIP2014 uoj20解方程 数论
- 下一篇: Atitit. 数据约束 校验 原理理论