1

Firefoxのhttpヘッダーアドオンで、ヘッダーと投稿コンテンツを記録しました。

ヘッダーは下にあります

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形式で送信されるようにします。

4

0 に答える 0