【问题标题】:Zoopla Sandbox with cURL http header errorZoopla 沙盒与 cURL http 标头错误
【发布时间】:2016-12-12 19:53:42
【问题描述】:

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

有人可以建议将配置文件添加到标题的正确方法吗?

感谢

【问题讨论】:

    标签: php http curl header


    【解决方案1】:

    从他们的示例看来,您应该将整个字符串作为单个 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'
    );
    

    【讨论】:

    • 感谢 iainn,做到了:- { "status" : "OK", "listings" : [], "branch_reference" : "test" } - 更仔细地观察的教训!
    猜你喜欢
    • 2017-04-19
    • 2016-04-27
    • 2017-07-11
    • 1970-01-01
    • 1970-01-01
    • 2023-04-10
    • 2015-07-17
    • 2016-04-17
    • 2012-11-07
    相关资源
    最近更新 更多