How to make a request to RESTFull webservice from php that n
Posted: Wed Mar 26, 2014 6:48 am
Please help me with this, I am using a webservice and i want the json data as response.
I have following code in my php file :
And i get output as :
[local_ip] => 127.0.0.1
[local_port] => 57616
I get 302 code and redirected to login page. How to get my json data from this request?
I am stuck from last 4 days. Please help me. Is there any way to make multiple requests using same context? Is there any thing similar like HttpContext(in java) for PHP?
I have following code in my php file :
Code: Select all
$url='http://localhost:8080/axelor-app/ws/rest/resourcepath/2';
$data=array('data'=>'{
"offset": 0,
"limit": 20,
"data": {
"_domain": "self.product LIKE :product",
"_domainContext": { "product": 1}
}
}');
curl_setopt($cURL, CURLOPT_URL, $url);
curl_setopt($cURL, CURLOPT_POST, 1);
curl_setopt($cURL,CURLOPT_POSTFIELDS ,$data);
curl_setopt($cURL,CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($cURL, CURLOPT_HTTPHEADER, array(
'Content-type: application/json',
'Accept: application/json'
));
$result1 = curl_exec($cURL);
print_r($result1);
print_r(curl_getinfo($cURL));
curl_close($cURL);
[primary_port] => 8080Array ( [url] => http://localhost:8080/axelor-app/ws/rest/resourcepath/2 [content_type] => [http_code] => 302 [header_size] => 270 [request_size] => 257 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.001812 [namelookup_time] => 7.0E-5 [connect_time] => 0.000118 [pretransfer_time] => 0.00012 [size_upload] => 287 [size_download] => 0 [speed_download] => 0 [speed_upload] => 158388 [download_content_length] => 0 [upload_content_length] => 287 [starttransfer_time] => 0.000916 [redirect_time] => 0 [redirect_url] => http://localhost:8080/axelor-app/login.jsp [primary_ip] => 127.0.0.1 [certinfo] => Array ( )
[local_ip] => 127.0.0.1
[local_port] => 57616
I get 302 code and redirected to login page. How to get my json data from this request?
I am stuck from last 4 days. Please help me. Is there any way to make multiple requests using same context? Is there any thing similar like HttpContext(in java) for PHP?