显示通过http post接收的变量


display variables received with http-post

我使用"curl"将一些变量从我的网站发送到远程URL:

$url = "a remote url";
$fields =array( variables );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$output = curl_exec ($ch);

if (!curl_exec($ch)) {
    echo 'An error has occurred: ' . curl_error($ch);
}
else {
    echo 'everything was successful';
}
curl_close ($ch);
echo $output;

我得到了"一切都很成功",但我不知道如何显示从远程URL接收到的变量。

有人能告诉我如何显示"$_POST"中的变量吗?我想检查变量是否正确发送到远程URL。

简单使用:

print_r( $_POST );

或者在"发送"脚本中,将字段显示为数组:

print_r( $fields );

假设您的CURL响应为纯文本:

variable1=value2
variable2=value3

您仍然可以这样查看您的回复:

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIESESSION, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields);
$output = curl_exec ($ch);

if (!curl_exec($ch)) {
    echo 'An error has occurred: ' . curl_error($ch);
}
else {
    $rows = explode("'n", $output);
    for( $i=0;$i<count($rows);$i++ )
    {
      $cols = explode('=', trim($rows[$i]) );
      print_r($cols);
    }
}
curl_close ($ch);
echo $output;