• HTTP


    今天遇到几个PUT上传的点,但是都没利用起来。一怒之下,在自己本地试了一下。步骤如下:

    一、环境:

    首先,根据 配置Apache服务器支持向目录PUT文件 更新一下httpd.conf文件,重启所有服务。

    二、HTTP - PUT

    PUT的前提,是了解HTTP协议。下面给出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:8080
    
    hello world

    要注意如下几个点:

    ① PUT方法是HTTP 1.1协议中才出现的。

    ② HTTP协议对空格敏感,每行数据的结尾不能出现空格

    ③ HTTP头部和数据中间要空一行,即HTTP头部是以 结尾的。

    ④ 端口号直接跟在HOST后面

    三、第一次PUT

    好了,现在可以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包的内容贴到命令行中,回车*/   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:8080 hello world
    /*发送的PUT包到此为止,以下为收到的数据包*/ 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是服务器内部错误啊。好吧好吧,我们去看看主机的Apache日志。

    四、再次配环境

    主机用的是WAMP,日志在/wamp/logs/apache_error.log。找到对应的那一条:

     

    通过浏览器搜索,又找到一篇日志。Linux(CentOS) 服务端搭建与配置,原来用HTTP - PUT还要添加一个什么锁。

    所以解决方法是:在Apache配置文件中,也就是httpd.conf,增加一行,设定webDAV锁位置。再次重启所有服务。
    DavLockDB  DavLock    #目录没有就创建(DavLock 为文件名,应该有的目录结构是wampinapacheApache2.2.21DavLock)
    五、终于成功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:8080
    
    hello 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 差不多这样,之后有更多关于PUT的经验,再分享

  • 相关阅读:
    Java实现 LeetCode 27 移除元素
    Java实现 LeetCode 26 删除排序数组中的重复项
    Java实现 LeetCode 26 删除排序数组中的重复项
    Java实现 LeetCode 26 删除排序数组中的重复项
    Java实现 LeetCode 25 K个一组翻转链表
    Java实现 LeetCode 25 K个一组翻转链表
    Java实现 LeetCode 25 K个一组翻转链表
    Java实现 LeetCode 24 两两交换链表中的节点
    Java实现 LeetCode 24 两两交换链表中的节点
    Java实现 LeetCode 24 两两交换链表中的节点
  • 原文地址:https://www.cnblogs.com/kuoaidebb/p/4466602.html
Copyright © 2020-2023  润新知