php - Zoopla 沙箱出现 cURL http header 错误

标签 php http curl header

我正在为房地产经纪人开发代码,以通过他们的数据源将特性上传到 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/

相关文章:

php session 变量多维关联数组问题

java - 如何在 JAVA 中使用 OAuth 2.0 获取/发布资源(状态代码 415)

web-services - 没有 session 的 HTTP 请求签名

curl - HTTP 网络跟踪到 cURL

php - SSL 与 CURL PHP 无法正常工作的 2 种方式

php - 如何将 Postman 授权 OAuth2 请求转换为代码 PHP 或可压缩过程

javascript - jQuery $.get() 不运行 php 脚本

php - 使用 Twig 和 PHPMailer

java - 如何在 HTTP 响应主体(使用 Spark)中发送 QR 码的 PNG?

android - TextView在OpenGl curl View 效果上不可点击