使用Guzzle http请求在Guzzle 7中获取API响应URL参数
我在网上搜索,但找不到适当的解决方案。我正在使用Guzzle Client拨打春季服务,以防其URL参数提供错误消息,例如: http:// localhost:8085/fedauth/null?errmessage = mot% 20DE%20PASSE%20Invalide%20POUR%20L& apos; litilisateur%20Karan%20sharma。
。如何使用Guzzle来获取此param errmessage
。以下是我的php中的Slim代码。
$data = [
'userName' => base64_encode($userName),
'userPassword' => base64_encode($userPassword),
'institution' => $institution,
'redirectUrl' => $redirectUrl,
'callerUrl' => $callerUrl,
'clientId' => $clientId,
'encryptMode' => $encryptMode,
'moodleLandPage' => $moodleLandPage,
'login' => $login,
'isEncrypted' => true
];
try {
$apiResponse = $client->post( $_ENV['FEDAUTH_API_URL'], ['form_params'=> $data]);
} catch (Exception $exception) {
return $response->write(json_encode(['error' => $exception->getMessage(), "auth" => "0" ]));
}
我尝试使用geteffectiveurl()方法,但在guzzle 7中不再支持它
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想您将响应作为重定向URL?在这一点上,您的问题尚不清楚。在这种情况下,您可以这样访问它:
就像:
I guess you get the response as a redirect url? Your question is not clear in that point. In this case you can access it like this:
like here: https://docs.guzzlephp.org/en/5.3/http-messages.html#responses
实际找到了答案。您需要添加Track Redirects选项为true,然后使用
$ response-> getheaderline('x-guzzle-redirect-History');
如下Actually found the answer. You need to add track redirects option as true and then use
$response->getHeaderLine('X-Guzzle-Redirect-History');
like below