2

cURLを使用してフォームに自動入力して送信しようとしています。コードはここにありますが、まったく何もしていません。

<?php
$post_data['countryID'] = '162';
$post_data['autocomplete'] = 'Assam, Karimganj';
$post_data['state'] = '3007';
$post_data['city'] = '60695';
$post_data['countryStateCityCase'] = '2';
$post_data['usesAutoComplete'] = '1';
$post_data['categoryParent'] = '185';
$post_data['categoryChild'] = '219';
$post_data['listing_type'] = '2';
$post_data['title'] = 'Title goes here';
$post_data['currency_typeC'] = '13';
$post_data['priceC'] = '2500';
$post_data['description']= 'Descriptio goes hereDescriptio goes hereDescriptio goes hereDescriptio goes here';
$post_data['email']= 'olx@test.com';
$post_data['ad_language_id']= '1';
$post_data['identity']= '1';
$post_data['imageQty']= '0';
$post_data['phone']= '03311234567';
$post_data['bddisclaimer']= '0';
$post_data['security_code']= 'undefined';
$post_data['captchaKey']= 'undefined';
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}
$post_string = implode ('&', $post_items);
echo $post_string;
$curl_connection =
  curl_init('http://www.olx.in/posting.php?src=8');

curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT,
  "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);

curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);

$result = curl_exec($curl_connection);
echo $result;
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
                curl_error($curl_connection);

curl_close($curl_connection);
?>

すべてのフィールドが正しく入力されていますが、何も出力されず、確認メールがまったく届きませんが、手動で正常に機能しています。誰かが私を助けてくれますか?

4

1 に答える 1

2

私の頭に浮かぶ最初の理由は、HTTPPOSTリクエストのコンテンツを構築しているときにパーセントエンコードを行っていないことです。urlencode(..)関数を使用して、キーと値のペアの値をエンコードできます。

交換

$post_items[] = $key . '=' . $value;

と:

$post_items[] = $key . '=' . urlencode($value);
于 2012-06-16T16:50:09.120 に答える