使用curl获取http post响应主体

时间:2011-09-11 19:03:30

标签: php 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.有没有办法在这里得到回复?

1 个答案:

答案 0 :(得分:8)

您缺少第一个参数:

curl_setopt($ch,CURLOPT_RETURNTRANSFER, true);