我需要使用pycurl发送HTTP HEAD请求。
此代码
curl = pycurl.Curl()
...
curl.setopt(curl.CUSTOMREQUEST, "HEAD")
curl.perform()
产生错误:
< HTTP/1.1 200 OK
* Server nginx/1.6.2 is not blacklisted
< Server: nginx/1.6.2
< Date: # No matters
< Content-Type: text/html; charset=utf-8
< Connection: keep-alive
< Cache-Control: no-cache,no-store,must-revalidate
< Pragma: no-cache
< Expires: # No matters
< Last-Modified: # No matters
< Content-Security-Policy: # No matters
< X-Frame-Options: SAMEORIGIN
< X-XSS-Protection: # No matters
< X-Content-Type-Options: nosniff
< Content-Encoding: gzip
* no chunk, no close, no size. Assume close to signal end
<
* Operation timed out after 15001 milliseconds with 0 bytes received
* Closing connection 1
有人能帮助我吗?
答案 0 :(得分:2)
您需要NOBODY选项。因为没有身体请。只是更改CUSTOMREQUEST并不会使libcurl改变其行为方式,并且它会认为它会执行GET但是您将其更改为HEAD然后事情就会变坏。
答案 1 :(得分:0)
只是澄清一下。你不需要做一个CUSTOMREQUEST!仅仅指定一个&#39; NOBODY&#39;选项足以让pycurl生成一个&#39; HEAD&#39;要求自己。使用PycURL / 7.43.0 libcurl / 7.51.0进行测试