在 firefox http headers 插件中,我记录了标题和发布内容。
标题在下面
Content-Type: multipart/form-data; boundary=---------------------------2794991859960663061251376577
帖子内容如下
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="action"\r\n
\r\n
post\r\n
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="_wp_http_referer"\r\n
\r\n
/submit/\r\n
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="cat"\r\n
\r\n
62\r\n
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="post_title"\r\n
\r\n
我转换成如下所示的卷曲。
$fields = '-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="action"\r\n
\r\n
post\r\n
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="_wpnonce"\r\n
\r\n
c9aa342328\r\n
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="_wp_http_referer"\r\n
\r\n
/submit/\r\n
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="cat"\r\n
\r\n
62\r\n
-----------------------------2794991859960663061251376577\r\n
Content-Disposition: form-data; name="post_title"\r\n
\r\n';
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US) AppleWebKit/525.13 (KHTML, like Gecko) Chrome/0.A.B.C Safari/525.13");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: multipart/form-data; boundary=---------------------------2794991859960663061251376577',
));
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch,CURLOPT_COOKIEJAR, "cookie.txt");
curl_setopt($ch,CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
$last = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$info = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($result,$last,$info);
curl_close($ch);
但是当我发现 http 标头时,它只发送 text/html
HTTP/1.1 200 OK Transfer-Encoding: chunked Date: Sun, 03 Mar 2013 11:38:01 GMT Server: LiteSpeed Connection: close X-Powered-By: PHP/5.2.17 X-Pingback: http://domain.com/xmlrpc.php Content-Type: text/html; charset=UTF-8 Expires: Wed, 11 Jan 1984 05:00:00 GMT Cache-Control: no-cache, must-revalidate, max-age=0 Pragma: no-cache Vary: User-Agent
我检查了 php.net 它说 If value is an array, the Content-Type header will be set to multipart/form-data.
现在如何将 $fields 转换为数组?这样数据将以 multipart/form-data 格式发送。