How to make a request to RESTFull webservice from php that n

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
sks11491
Forum Newbie
Posts: 1
Joined: Wed Mar 26, 2014 6:42 am

How to make a request to RESTFull webservice from php that n

Post by sks11491 »

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 :

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);
And i get output as :
Array ( [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 ( )
[primary_port] => 8080
[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?
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: How to make a request to RESTFull webservice from php th

Post by Christopher »

If you go to that URL directly, are you also redirected? Are you required to be logged-in to access that URL?
(#10850)
Post Reply