我正在为房地产经纪人开发代码,以通过他们的数据源将特性上传到 Zoopla
我在将所需的配置文件添加到所需的 http header 时遇到问题
文档中唯一的示例是来自 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 header 时遇到问题 这是我的代码:
$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" }
有人可以建议将配置文件添加到标题的正确方法吗?
谢谢
最佳答案
从他们的示例来看,您似乎应该将整个字符串作为单个 Content-Type
HTTP header 传递,而不是两个单独的 header :
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'
);
关于php - Zoopla 沙箱出现 cURL http header 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38355916/