Chathura
Chathura

Reputation: 11

consuming two consequence Rest web serivce using PHP, curl or file_get_contents?

I need to first use webservice to login and then set the cookie in browser, then call another webservice and get some user specific data.

When I paste rest webservice on browser (first logging, then another one to get user specific data) it works fine.

But if I call those two web services using php (used twice) with

file_get_contents("url to login");
$Userdata=file_get_contents("url to get user specific data");

it seems $Userdata has no data, as if previous line file_get_contents("url to login"); has not been executed.

Any idea how to do this?

Upvotes: 1

Views: 168

Answers (1)

Kuitsi
Kuitsi

Reputation: 1675

You can send cookie with get_file_contents via stream context (see PHP - Send cookie with file_get_contents) but if you want to use the cookie to log in, you have to somehow grab the cookie set by first request. It could be easier to use cURL. There is other question with accepted answer to describe this with cURL: file_get_contents receive cookies

Upvotes: 1

Related Questions