last day (14 days later) » 

6:46 AM
2
A: Extra garbage values added when posting JSON data using cURL

Sahil GulatiYou need to give array in json_encode, Instead of string. Replace: $field_string = "{“Request”: “Login”, “Username”: anonymous, “APIAccessKey”: “AW342FFGRTR56RTH”, “GMT-Timestamp”: “1489670000”}"; $json = json_encode($field_string); To: $field_string= '{ "Request": "Login", "Use...

 
I am getting this as response '"{\\r\\n___\\"Request\\":_\\"Login\\",\\r\\n___\\"Username\‌​\":_\\"anonymous\\",‌​\\r\\n___\\"API‌​Acces‌​sKey\\":_\\"AW342FFG‌​RTR56RTH\\",\\r\\n__‌​_\\"GMT-Timestamp\\"‌​:_\\"1489670000\\"‌​\\‌​r\\n}"' => '', 0 => '', )
 
I have corrected all the mistakes in your code.. Might the api on which you are requesting is not working properly. try to use this {"Request": "Login", "Username": "anonymous", "APIAccessKey": "AW342FFGRTR56RTH", "GMT-Timestamp": "1489670000"} Json. I am providing you the complete curl request try to check with that also on terminal
I have corrected above json of comment. check now
 
@ sahil now i get this '{""{\\"Request\\":_\\"Login\\",_\\"Username\\":_\\"anonymou‌​s\\",_\\"APIAccessKe‌​y\\":‌​_\\"AW342FFGRTR‌​56RTH\\",_\\"GMT-Tim‌​estamp\\":_\\"148967‌​0000\\"}"":"","0":""‌​}' and when i check in json validator it shows invalid
Also i want to know how to get rid of these `` at a time, i tried using stripslashes but it does not remove all the slash
 
i want to ask one thing are doing json_encode again ? you dont need to do json_encode because this {"Request": "Login", "Username": "anonymous", "APIAccessKey": "AW342FFGRTR56RTH", "GMT-Timestamp": "1489670000"} is already a json
 
Hi
 
6:46 AM
yes try it now
 
I was doing so because i wanted to decode the POST values i Get from client
I removed the json_decode
and i got this
'"{\\"Request\\":_\\"Login\\",_\\"Username\\":_\\"anonymous\\",_\\"APIAccessKey\\":_\\"AW34‌​2FFGRTR56RTH\\",_\\"GMT-Timestamp\\":_\\"1489670000\\"}"' => '', 0 => ''
 
just read my post please do as it is mentioned
 
is this correct ?
$url = 'http://172.24.130.50/testbiz/server/login';


$field_string= '{"Request": "Login", "Username": "anonymous", "APIAccessKey": "AW342FFGRTR56RTH", "GMT-Timestamp": "1489670000"}';
$json = json_encode($field_string);
//open connection
$ch = curl_init();
 
no
remove this line
$json = json_encode($field_string);
 
which one
okay
now i get this when var_dump
array ( '{"Request":_"Login","Username":"anonymous","APIAccessKey":"AW342FFGRTR56RTH‌​","GMT-Timestamp":"1489670000"}' => '', 0 => '', )
 
6:51 AM
try this on terminal
curl -XPOST 172.24.130.50/testbiz/server/login -d '{"Request": "Login", "Username": anonymous, "APIAccessKey": "AW342FFGRTR56RTH", "GMT-Timestamp": "1489670000"}'
 
ok
I get this
there is extra _ and some extra obj appended at the end of json 0=> ''
 
now i must say
Please look it into that url
might that url has problem
ingeither they need some headers or someth
either they need some headers or something
Please check the api docs of that
 
i have used no API i am just trying to use plain CURL
see i am posting the whole code
<?php

/**
*
*/
class Client extends MY_Controller
{

public function __construct()
{
parent::__construct();
}


public function index()
{
$url = 'http://172.24.130.50/testbiz/server/login';


$field_string= '{"Request": "Login", "Username": "anonymous", "APIAccessKey": "AW342FFGRTR56RTH", "GMT-Timestamp": "1489670000"}';

//open connection
$ch = curl_init();

//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, 1);
curl_setopt($ch,CURLOPT_POSTFIELDS, $field_string);
and on SERVER i have this
<?php

class Server extends MY_Controller
{

public function __construct()
{
parent::__construct();
}

public function login()
{

$client_data = $this->input->post();

var_dump($client_data);
}
}
 
7:09 AM
i am looking into this
 
7:48 AM
oky
thanks
 

last day (14 days later) »