Uploading historical data via PHP501

JoEmbedded private msg quote post Address this user
Hi Forum!

I have an account where a data logger sends the collected data as one block (with ultra low power via 2/3/4G) to an intermediate server. From there times/values are extracted and shall be inserted to my account. (Device: clickable text )

The "direct way" works:

However if sending the old data via PHP/JSON I always get "Unsupported Media Type". I tested it with a small sample script:

// data
$component=array("stream" => $data_c,  "compId" => "Tbuero");
$feed=array("startTime"=> time()*1000, "component" => $component);
$gs=json_encode(array("feed" => $feed));
// URL
$gs_api_key="68312ae5-XXXX-3e9d-8f4c-615a10d836f3"; // FEED
// CURL 
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS,$gs);
curl_setopt($ch, CURLOPT_TIMEOUT,15);	// opt. seconds timeout (for Tests)
$response = curl_exec($ch);
echo $response;

which sends:

PUT /api/feed?api_key=68312ae5-XXXX-3e9d-8f4c-615a10d836f3 HTTP/1.1
Accept: */*
Content-Length: 96
Content-Type: application/x-www-form-urlencoded

What am I doing wrong?
Thanks for your help!
Post 1 IP   flag post
MikeMills private msg quote post Address this user
I think Unsupported Media type means the content-type header needs to be set. Try setting the header: content-type:application/json

Here's a GS Python example:
Post 2 IP   flag post
2965 2 2
Log in or sign up to compose a reply.