由于我是 PHP 新手,所以我很难使用 PHP。问题是我没有从curl 请求中获得任何返回值。我正在访问一个远程文件,其中包含以下代码:
测试.php:
$test->getCall();
public function getCall() {
$var = array('fname'=>'jack','lname'=>'williams');
return $var;
}
我拨打电话的脚本。
请求值.php
try{
$ch = curl_init();
if (FALSE === $ch){
throw new Exception('failed to initialize');
}
curl_setopt($ch, CURLOPT_URL,"http://www.xyz.com/app/src/test.php");
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $msg);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
$p_result = curl_exec($ch);
var_dump($p_result);
print_r($p_result);
if (FALSE === $p_result) {
throw new Exception(curl_error(), curl_errno());
curl_close($ch);
} else{
curl_close($ch);
return $p_result;
}
}catch(Exception $e) {
trigger_error(sprintf('Curl failed with error #%d: %s',$e->getCode(), $e->getMessage()),E_USER_ERROR);
}
我没有得到任何价值$p_result
也不例外curl_error()
.