I do an HTTP POST to a server and I am trying to get the value of session_token out of the results below how can i do that?
My post:
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_POST, true);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt( $ch, CURLOPT_HTTPHEADER, array('X-HTTP-Method-Override: POST','Content-Type:application/x-www-form-urlencoded','Content-Length: ' . strlen(http_build_query($data))));
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLINFO_HEADER_OUT, true);
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER, false);
$response = curl_exec( $ch );
print_r($response);
the response:
HTTP/1.1 200 OK
Date: Tue, 07 Jul 2015 19:12:25 GMT
Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i mod_wsgi/3.5 Python/2.7.8
Content-Length: 180
Content-Type: application/json
{"guid": null, "session_token": "0kndD67A0dptosqodpSuCUoAsrNxTxnMqme29Grkx0sKaXEKH3wYAis6arOkH4ETHf6ytC8UNotBhwsPM61jJWqnX1mXbhBFlJI8z56yBA6dPUVaynta0LvrNUgZxwc5", "success": true}
I have tried json_decode but that returns null.
php://input.Content-Type: application/x-www-form-urlencodedandContent-Length. Because ofcurl_setopt($ch,CURLOPT_POSTFIELDS, http_build_query($data));, curl sets them for you.