在Geckoboard php curl中获取无效的JSON错误

I am trying to add data in Geckoboard dataset using php curl but i am getting invalid json error. Please help me.

Please check my below code:

$ch = curl_init('https://api.geckoboard.com/datasets/sales.datasetidhere/data');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$data = array("articlePublished" => "6"); 
$data = json_encode($data);
curl_setopt($ch, CURLOPT_POST, 1); 

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_TIMEOUT, 100);
curl_setopt($ch, CURLOPT_USERPWD, "Key:");

curl_setopt( $ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
# Return response instead of printing.
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, true );

curl_setopt($ch, CURLOPT_POSTFIELDS, 'data='.$data);

$response = curl_exec($ch);
$headers = curl_getinfo($ch);
print_r( $headers );
print_r( $response );

Here is the response: {"error":{"message":"Invalid JSON was received by the server."}}

dongling2038
dongling2038 这有没有解决?有一个类似的问题。
一年多之前 回复
dongxie3701
dongxie3701 使用json_encode后仍无法正常工作
3 年多之前 回复
dougutuo9879
dougutuo9879 什么是json_encodecode?它应该是json_encode
3 年多之前 回复
dongwei2983
dongwei2983 json_encodecode不是标准函数。它有什么作用?
3 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐