次のコードでページを送信する POST を作成しようとしています。
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://www.olx.es/posting_success.php");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTREDIR, 2);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, array("itemid" => $json['id'], "sh" => $json['sh']));
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/x-www-form-urlencoded"));
$response = curl_exec($ch);
curl_close($ch);
そうすることで、「無効なリクエスト」というサーバーエラーが返されました。
telnet で手動でリクエストを行うと、最初に 302 を返したことに気付きました。仕事ではなく、彼をフォローするように設定したにもかかわらず、おそらくこれです。
顧客が実際に送信したものを Wireshark で取得した場合、何が間違っているのでしょうか?
**Hypertext Transfer Protocol:**
POST /posting_success.php HTTP/1.1
Host: www.olx.es
Connection: keep-alive
Content-Length: 52
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Origin: http://www.olx.es
User-Agent: Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.31 (KHTML, like Gecko) Chrome/26.0.1410.64 Safari/537.31
Content-Type: application/x-www-form-urlencoded
Referer: http://www.olx.es/posting.php?categ_id=322
Accept-Encoding: gzip,deflate,sdch
Accept-Language: es-ES,es;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
**Line-based text data: application/x-www-form-urlencoded:**
itemid=501347053&sh=b9302ed20769ae3717f896a33a369aa2
私の英語でごめんなさい..