Yii2如何将表单请求发送到外部url [英] Yii2 how to send form request to external url

查看:66
本文介绍了Yii2如何将表单请求发送到外部url的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何向外部网址发送重定向帖子请求?我在控制器中的代码:

 if ($model->load(Yii::$app->request->post()) && $model->validate()) {//发送post请求到外部链接}

解决方案

您需要使用 307 状态代码,用于指定应该使用相同 POST 数据执行的重定向.

$this->redirect('https://example.com', 307);

<块引用>

HTTP 307 Temporary Redirect 重定向状态响应代码表示请求的资源已临时移动到 Location 标头给出的 URL.

重用原始请求的方法和正文来执行重定向的请求.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307

How to send a redirect post request to external url? my code in controller:

    if ($model->load(Yii::$app->request->post()) && $model->validate()) {
      // send post request to external link
    }

解决方案

You need to use 307 status code to specify redirection which should be performed with the same POST data.

$this->redirect('https://example.com', 307);

The HTTP 307 Temporary Redirect redirect status response code indicates that the resource requested has been temporarily moved to the URL given by the Locationheaders.

The method and the body of the original request are reused to perform the redirected request.

https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/307

这篇关于Yii2如何将表单请求发送到外部url的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆