我试图弄清楚为什么我在发布到网址时收到无效的布尔错误。错误和代码如下。
我们非常感谢您的想法,我也可以提供更多细节。
错误回复:
Array(
[error] => Array (
[errorCode] => 1008
[errorType] => Validation
[errorMessage] => Invalid boolean value
[obj] => collectionOnDelivery
)
[data] =>
)
代码:
$client = new Zend_Http_Client($url);
$client->setMethod(Zend_Http_Client::POST);
$client->setHeaders('Host', 'url.api.com');
$client->setHeaders(Zend_Http_Client::CONTENT_TYPE, 'application/json');
$client->setHeaders('Accept', 'application/json');
$client->setHeaders('Content-Length', strlen($payload));
$client->setParameterPost(
array(
'collectionOnDelivery' => false,
'jobId' => null,
'invoice' => null,
'collectionDate' => $date,
'consolidate' => false,
'consignment', $payload
));
$response = $client->request();
API文档
Example Request is shown below:
POST /url HTTP/1.1
Host: url.api.com
Content-Type: application/json
Accept: application/json
Content-Length: 2416
{
"job_id": null,
"collectionOnDelivery": false,
"invoice": null,
"collectionDate": "2012-05-01T09:00:00",
"consolidate": false,
"consignment": [{ // Array of details about consignment }]
}
发布参数
collectionOnDelivery boolean
寄售对象[]
collectionDate date
合并布尔值
答案 0 :(得分:1)
HTTP Post值是字符串,因此当您尝试传递布尔值时,您会收到错误。尝试用字符串替换你的布尔值:
'collectionOnDelivery' => "false",
答案 1 :(得分:0)
我最终更改为setRawData
作为发送JSON数据的正确方法。
setRawData
第一次失败的原因是因为它需要寄售数组在另一个数组中。将[{
翻译成PHP是我最后的错误,这是一个双数组。
$content = array(
'collectionOnDelivery' => false,
'job_id' => null,
'invoice' => null,
'collectionDate' => $date,
'consolidate' => false,
"consignment" => array(array(/*ARRAY OF DETAILS*/)));
$payload = Zend_Json::encode($content);
然后将帖子设置如下
$client->setRawData($payload);