簡體   English   中英

如何重定向當前頁面以使用 guzzle (laravel) 發布響應

[英]How can I redirect current page to post response with guzzle (laravel)

例如,我有一個表格:

<form method='post' action='https://test.com'>
<input name='name' value='test'>
<button name='test' type='submit'> </button>
</form>

提交后,這會將我重定向到另一個頁面。 我的問題是“我怎樣才能用控制器的 guzzle 做同樣的事情?” 我試着做:

$client =         $client = new GuzzleHttpClient();
$response = $client->post('https://test.com', 
form_params => [
    'name' => 'test'
]);
return $response->getBody()->read(1024);

在這里,我得到了我想要的回應。 但我想將當前頁面重定向到帶有響應的頁面。

在方法控制器中使用return redirect()->back()

你必須嘗試這樣的事情

 $client = $client = new GuzzleHttpClient();
 $response = $client->post('https://test.com', 
 form_params => [
  'name' => 'test'
]);
$response_to_return = $response->getBody()->read(1024);

return redirect()->back()->withInput()->with('response_to_return', $response_to_return);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM