使用curl获取HTTP post响应体


getting http post response body using curl

所以我有以下代码片段

$ch = curl_init();
//Set the URL
curl_setopt($ch, CURLOPT_URL, $jURL);
//Enable curl response
curl_setopt(CURLOPT_RETURNTRANSFER, true);
//Enable POST data
curl_setopt($ch, CURLOPT_POST, true);
//Use the $pData array as the POST data
curl_setopt($ch, CURLOPT_POSTFIELDS, $jData);
$result = curl_exec($ch);
echo 'The body of the response is ' . $result;
curl_close($ch);

我想让响应体打印出来,但是我上面的代码打印数字1。有办法在这里得到响应吗?

您错过了第一个参数:

curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);