0

curl を使用して、website1 から website2 にデータを送信しています。

その後、受信側でデータを送信すると、次のようになります

Array
(
    [ip] => 112.196.17.54
    [amp;email] => test@test.com
    [amp;user] => test123,
    [amp;type] => point
    [amp;password] => password
)

私によると http_build_query() 、間違った結果が生成されます。

「ip」フィールドは正しい残りは正しくありません。

なぜそれが起こるのか教えてください。

curl 関数は以下のとおりです: http_build_query($config)

function registerOnPoints($username ,$password,$email,$ip ,  $time )
{

    $ch = curl_init("http://website2c.com/curl-handler");

    curl_setopt(

    $ch, CURLOPT_RETURNTRANSFER, 1);



    $config = array( 'ip' => $ip, 
                     'user' => $username, 
                     'email' => $email,
                     'password'=> $password,
                     'time' =>  $time,
                     'type' => 'point') ;

    # add curl post data                 
    curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($config));
    curl_setopt($ch, CURLOPT_POST, true);

    # execute 
    $response = curl_exec($ch);
 
    # retreive status code
    $http_status = curl_getinfo($ch , CURLINFO_HTTP_CODE);

   if($http_status == '200')
   {
      $response = json_decode($response);

    } else {
       echo $http_status;
    }


   // Close handle
   curl_close($ch);

}

それがphpバージョンの問題である場合、明確に言えば、curl関数のみがエラーを生成しているため、phpのバージョンを変更する権限がありません残りのプロジェクトは完了し、期待どおりに動作しています。私を助けてください。

4

1 に答える 1

7

私はあなたが試すことができると思います:

http_build_query($config, '', '&');

または代替:

$paramsArr = array();

foreach($config  as $param => $value) {
   $paramsArr[] = "$param=$value";
}

$joined = implode('&', $paramsArr);
//and use
curl_setopt($ch, CURLOPT_POSTFIELDS, $joined);
于 2013-02-22T11:43:13.280 に答える