跳至主要內容
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?

4563博客

全新的繁體中文 WordPress 網站
  • 首頁
  • flask 如何跳转到第三方页面, 要 post 数据.
未分類
25 5 月 2020

flask 如何跳转到第三方页面, 要 post 数据.

flask 如何跳转到第三方页面, 要 post 数据.

資深大佬 : l4ever 62

用 redirect 只能跳转, 但是无法 post 数据过去啊.
大佬有話說 (16)

  • 資深大佬 : bolide2005

    还是再详细描述一下你的场景吧。

    redirect 而又携带原方法的,我记得是用状态码 307 实现的,不过一般的 web framework 都不这么做(?),你要非得用的话估计得自己制定状态码,这还要看第三方服务支持不支持 307。

    而且 redirect 又 post,这是一种什么场景呢?

  • 資深大佬 : bolide2005

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

    “The only difference between 307 and 302 is that 307 guarantees that the method and the body will not be changed when the redirected request is made. With 302, some old clients were incorrectly changing the method to GET: the behavior with non-GET methods and 302 is then unpredictable on the Web, whereas the behavior with 307 is predictable. For GET requests, their behavior is identical.”

    注意看这里的 302 和 307 的区别

  • 主 資深大佬 : l4ever

    @bolide2005 我是想通过访问一个 flask 写的页面生成一段 token, 通过 token 登录第三方网站.
    我首先想到的是 redirect(‘http://xxx.com/login/?token=xxxxx’)
    这是 get 当然可以

    但是如果是 post, 第三方网站只能 post 请求
    如何把我的 tokenpost 到 http://xxx.com/login/ 并跳转.实现登录

  • 資深大佬 : bolide2005

    @l4ever #3
    redirect 的方法有一个参数 code 是用来制定状态码的,传入 307 试试?
    不过你这种用法又不一样了,相当于又修改了 browser 传入的 body,能不能行我就不确定了,可以自己起个服务测测

  • 資深大佬 : bolide2005

    制定 -> 指定

  • 資深大佬 : bolide2005

    我想了想,八成是不行的。

    redirect 其实是通过状态码要求 browser 进行某种重新请求,你修改的 body 是没办法传给 browser 的,这条路估计走不通。

  • 主 資深大佬 : l4ever

    @bolide2005 redirect 应该做不到. 不知道 flask 有没有其他的方法能做到.

  • 主 資深大佬 : l4ever

    我想了一下, 跳到自己的页面. 用 js 提交这个 form 可以做到. 但这样太不科学了.

  • 資深大佬 : jowan

    用 flash 生成 form 表单自动提交过去就行了 参考支付宝的 SDK

  • 資深大佬 : jowan

    你下载支付宝网页支付的 SDK 就知道了 他自己就是生成 form 表单跳转过去的
    你 flask 也可以在 template 里面生成表单自动提交

  • 資深大佬 : bolide2005

    @l4ever #8
    第三方是自己的服务吗?
    如果不是的话你这样做会遇到跨域的问题。

  • 資深大佬 : leishi1313

    做不到的,你要登录第三方人家凭什么让你一个 token 就能登上。你要是 redirect 到第三方登录页然后用户名 /密码自动填充还差不多

  • 資深大佬 : ipwx

    如果第三方页面不是你控制的,一个 csrf token 就能让你无法可行

  • 主 資深大佬 : l4ever

    “`
    return f”””
    <title>LOADING</title>
    <body onload=”document.forms[0].submit();”>
    <form id=”sso” action=”xxx.com” method=”POST”>
    <input type=”hidden” value=”{token}”>
    </body>
    “””
    “`
    可以了.

  • 主 資深大佬 : l4ever

    @leishi1313
    @ipwx 本帖不讨论安全

  • 資深大佬 : Lax

    用脚本 form.submit 吧。在浏览器发生的跳转,POST 又注定不能用 redirect 和 location.href。

文章導覽

上一篇文章
下一篇文章

AD

其他操作

  • 登入
  • 訂閱網站內容的資訊提供
  • 訂閱留言的資訊提供
  • WordPress.org 台灣繁體中文

51la

4563博客

全新的繁體中文 WordPress 網站
返回頂端
本站採用 WordPress 建置 | 佈景主題採用 GretaThemes 所設計的 Memory
4563博客
  • Hostloc 空間訪問刷分
  • 售賣場
  • 廣告位
  • 賣站?
在這裡新增小工具