I've been trying to get json and some header elements using this code: And I was able to print the details that I need but it seems that I can't actually "get" them.
$url = 'http://192.168.254.211:8080/sampleOnCurl/auth/login';
$initCurl = curl_init($url);
curl_setopt_array($initCurl,
array(
CURLOPT_URL => $url,
CURLOPT_POST => true,
// CURLOPT_NOBODY => true,
CURLOPT_RETURNTRANSFER => true,
// CURLOPT_FOLLOWLOCATION => true,
CURLOPT_POSTFIELDS => $loginData,
CURLOPT_HEADER => true,
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json',
'jrr: 7ffed684cbe1fc085b7b47dc4e508e99a5effee9',
'slave: 01bdfcc20777907712e97f7bd2faeb978584f317',
'spoil: ' .$timeStamp
)
)
);
$result = curl_exec($initCurl);
print_r($result);
//prints jrr, slave, spoil
$result = json_decode($result);
// $header = curl_getinfo($initCurl);
curl_close($initCurl);
and this is what I get
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
jrr: 2e278657295bdfae2bc49b0bc6ad38363e9b149b
slave: d77985811796708b89471b4d29a904b224d41dde
spoil: 20130916222842701
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Date: Mon, 16 Sep 2013 14:28:42 GMT
{"true":null}
I want to get {"true":null} and convert it to array to check if index is true
and get jrr, slave and spoil values .. without using the get method ..
The string that is printed doesn't seem to be in json as well. My guess is that the problem is in my curl options. What could I be missing out?
Here's what I need to do:
get the json {"true":null}
get the Response Header: jrr, slave, spoil
avoid using Get method
thanks
HEADto get headers (server will interpret it likeGETbut will not send content in response). But to get JSON you have to useGETorPOST.GETbecause the server will return me an error onlyPOSTis allowed. On that note specifically whatHEAD?But to get JSON you have to use GET or POSTcould please elaborate ? as you can see the reponse I get doesn't seem to be in JSON format.. and I can't access them using$result['jrr']{"true":null}is valid JSON, what is problem with that? You can also usejson_decode($result, true)to force array format.HEADis next request method (likePOSTorGET), it gets only headers, but you said that onlyPOSTis allowed so you can forget about it in that case.$result = json_decode($result)beforeprint_rthe page doesn't print anything and I think that{"true":null}is part of$resultif that makes any sense