我有以下类,它使用Web服务发送请求并获取JSON响应。 当我使用Chrome的Postman扩展程序尝试相同的操作时,我得到了一个很好的回复。
class RequestController {
function __construct() {
global $config;
$this->config = $config;
}
function send_request() {
$url = $this->config['GATEWAY']['url'] . 'getbyquery';
$json_data = '{"query":{"AllFields":true,"ConditionSetOperator":0,"ConditionSets":[],"Distinct":false,"Fields":["jay_alb","jay_levelms"],"Links":[],"Orders":[],"RecordType":"jay_lifeinsurance","Top":0}}';
$data = array($json_data);
$options = array(
'http' => array(
'header' => "Content-type: application/json\r\n",
'method' => 'POST',
'content' => http_build_query($data),
),
);
$context = stream_context_create($options);
print "<pre>";
print_r($options);
print "</pre>";
$result = file_get_contents($url, false, $context);
$data = json_decode($result);
var_dump($data);
}
}
然而,当我使用我的课时,我得到一个错误。
警告:file_get_contents(http://crm-gateway.premier.com.au/GatewayService.svc/getbyquery)[function.file-get-contents]:无法打开流:HTTP请求失败!在第32行的C:\ Program Files(x86)\ Apache Software Foundation \ Apache2.2 \ htdocs \ crm \ includes \ classes \ RequestController.php中需要HTTP / 1.1 411长度
你能指出我做错了吗?
谢谢,