Php cURL的响应为{“error”:“Content type”application/x-www-form-urlencoded“not supported”}
我在ZF2 php中使用cURL将JSON数组发布到url 在下面添加带有JSON数组的代码Php cURL的响应为{“error”:“Content type”application/x-www-form-urlencoded“not supported”},php,json,zend-framework,curl,Php,Json,Zend Framework,Curl,我在ZF2 php中使用cURL将JSON数组发布到url 在下面添加带有JSON数组的代码 $data = <<< JS { "runFolder": "141015_7001367R_0388_AHANRLADXX", "sequencingMetricsProfile": "partner_run_level", "barcodeSet": "partner_barcode_set", "sequencingSamples": [ { "sequenc
$data = <<< JS
{
"runFolder": "141015_7001367R_0388_AHANRLADXX",
"sequencingMetricsProfile": "partner_run_level",
"barcodeSet": "partner_barcode_set",
"sequencingSamples": [
{
"sequencingSampleId": "sample1",
"lanes": [1,2],
"barcodeSequence": "AGCTTGA",
"targetSets": [
"partner_cnc"
],
"sequencingSampleMetricsProfile": "partner_metrics_sample_level"
},
{
"sequencingSampleId": "sample2",
"lanes": [1,2],
"barcodeSequence": "AGCTTGT",
"targetSets": [
"partner_cnc"
],
"sequencingSampleMetricsProfile": "partner_metrics_sample_level"
}
]
}
JS;
$adapter = new Curl();
$client = new Client();
$client->setAdapter($adapter);
$client->setUri('https://api.xxxxxxxxxxxx.com/2.0/xxxx/sequencingAnalysis');
$client->setMethod('POST');
$adapter->setCurlOption(CURLOPT_POST, 1);
$adapter->setCurlOption(CURLOPT_POSTFIELDS, $data);
$adapter->setCurlOption(CURLOPT_SSL_VERIFYPEER, 0);
$adapter->setCurlOption(CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Authorization: Bearer ' . $token
));
$response = $client->send();
print $response->getStatusCode();
print $response->getBody();
print_r($response);
但响应称为{error:Content type'application/x-www-form-urlencoded'notsupported}
标题有什么问题吗?
或者JSON中的任何问题
请帮助您似乎将标题设置正确,但发送的标题错误。如果我是你,我会切换到普通卷曲,那个库的麻烦比它的价值还多。@pguardiario,你是对的。它在普通卷曲中工作