转的文章。主要是因为经常会用curl来抓取数据。而且几乎是http_get和http_post混用。但我没遇上这个BUG。不清楚以后会不会遇上,所以我先记录一下,以防万一遇到时候不知道怎么做。 原文地址来自:http://www.ideawu.net/blog/archives/622.html 重用一个CUR
转的文章。主要是因为经常会用curl来抓取数据。而且几乎是http_get和http_post混用。但我没遇上这个BUG。不清楚以后会不会遇上,所以我先记录一下,以防万一遇到时候不知道怎么做。
原文地址来自:http://www.ideawu.net/blog/archives/622.html
重用一个CURL句柄时, 发现curl_setopt($ch, CURLOPT_HTTPGET, TRUE) 不起作用. 期望在调用这条语句之后发起请求, 应该发送的是GET, 但看服务器log, 却使用了和前一次请求相同的HTTP方法.
PHP脚本:
<?php $url = 'http://www.ideawu.net/'; $ch = curl_init($url); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST"); curl_exec($ch); curl_setopt($ch, CURLOPT_HTTPGET, true); // 错误! BUG curl_exec($ch); curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET"); // 正确 curl_exec($ch); ?>
web server log:
124.127.130.50 "2011-10-12 18:55:09" "POST / HTTP/1.1" 200 3516 "-" www.ideawu.net 124.127.130.50 "2011-10-12 18:55:09" "POST / HTTP/1.1" 200 3516 "-" www.ideawu.net 124.127.130.50 "2011-10-12 18:55:09" "GET / HTTP/1.1" 200 3516 "-" www.ideawu.net
这个BUG目前还没找到相关的资料.
补充: 不仅仅是CURLOPT_HTTPGET, CURLOPT_POST也有同样的问题. 所以, 结论是: 只有CURLOPT_CUSTOMREQUEST才是正确的方法.
原文地址:转:2011-10-12 PHP重用curl句柄, CURLOPT_HTTPGET的BUG, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

WebStorm Mac version
Useful JavaScript development tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft