简体   繁体   English

消耗两个结果使用PHP,curl或file_get_contents进行其余的Web服务吗?

[英]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. 我需要首先使用Web服务登录,然后在浏览器中设置Cookie,然后调用另一个Web服务并获取一些特定于用户的数据。

When I paste rest webservice on browser (first logging, then another one to get user specific data) it works fine. 当我将其余的Web服务粘贴到浏览器上时(先记录日志,然后再记录另一个以获取用户特定的数据),它可以正常工作。

But if I call those two web services using php (used twice) with 但是,如果我使用php(两次使用)调用这两个Web服务,

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"); 似乎$Userdata没有数据,就像上一行file_get_contents("url to login"); has not been executed. 尚未执行。

Any idea how to do this? 任何想法如何做到这一点?

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. 您可以通过流上下文发送带有get_file_contents cookie(请参阅get_file_contents 使用file_get_contents发送cookie ),但是如果要使用cookie登录,则必须以某种方式获取第一个请求设置的cookie。 It could be easier to use cURL. 使用cURL可能会更容易。 There is other question with accepted answer to describe this with cURL: file_get_contents receive cookies 还有一个问题,它的答案可以用cURL来描述: file_get_contents接收cookie

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM