Zoopla Sandbox与cURL http标头错误

时间:2016-07-13 15:28:37

标签: php http curl header

我正在为地产代理开发代码,通过他们的数据源将属性上传到Zoopla

我在向http标头添加所需的配置文件时遇到问题

文档中唯一的例子是来自linux的测试:

echo '{ "branch_reference" : "test" }' |
curl --key /path/to/private.pem --cert /path/to/certificate.crt --data @-
--header "Content-type: application/json;
profile=http://realtime-listings.webservices.zpg.co.uk/docs/v1.1/schemas/listing/list.json"
https://realtime-listings-api.webservices.zpg.co.uk/sandbox/v1/listing/list

我在将配置文件添加到cURL中的http标头时遇到问题 这是我的代码:

$json['branch_reference']="test";
$json=json_encode($json);

$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_SSLKEY,'private.pem');
curl_setopt($ch, CURLOPT_SSLCERT,'zpg_realtime_listings_1468337696150754_20160712-20260710.crt');
curl_setopt($ch, CURLOPT_URL, "https://realtime-listings-api.webservices.zpg.co.uk/sandbox/v1/listing/list");
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/json', 
  'profile: http://realtime-listings.webservices.zpg.co.uk/docs/v1.1/schemas/listing/list.json'
  ));
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json);
if(curl_error($ch)){echo "CURL ERROR ".curl_error($ch)."<br>";}
$result = curl_exec($ch);
curl_close($ch);

echo $result;

我从Zoopla得到的回应是:

{ "error_advice" : "The Content-Type header is missing the 'profile' parameter. Please supply 'profile', specifying the schema URL for the method you are calling: /sandbox/v1/listing/list", "error_name" : "missing_profile" } 

有人可以告诉您将标题添加到标题的正确方法吗?

感谢名单

1 个答案:

答案 0 :(得分:2)

从他们的示例中,看起来您应该将整个字符串作为单个Content-Type HTTP标头传递,而不是两个单独的标头:

curl_setopt($ch, CURLOPT_HTTPHEADER, array(
  'Content-Type: application/json; profile=http://realtime-listings.webservices.zpg.co.uk/docs/v1.1/schemas/listing/list.json'
);