V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
xavierskip
V2EX  ›  问与答

iOS 快捷指令里用获取 URL 内容出现了诡异现象, GET 请求正常, POST 请求无反应??

  •  
  •   xavierskip · 2023-03-12 12:05:24 +08:00 · 748 次点击
    这是一个创建于 411 天前的主题,其中的信息可能已经有所发展或是发生改变。

    不是有利用 chatGPT 让 siri 更加智能的快捷指令吗? 我给 openai 的 api 做了反向代理,在其他的应用里都用着好好的。但是唯独修改快捷指令里的 api url 就没反应了。

    我先是在本地 PC 上开了一个 web 服务器,看我写的快捷指令的请求能否正常工作,一切正常,get 请求和 post 请求都可以。 我还在路由器及服务器上抓了包,看起来也正常,http 请求很简单但是 https 的 tls 协议就看不太懂了,但是有看到数据包至少没被防火墙挡住。

    最后就直接在代理服务器上开个测试的 web 服务器,nginx 配置好 proxy_pass ,结果 GET 请求就能正常返回,但是 POST 请求就无反应,nginx 日志里也没有。而且 http 访问一切正常,https 就不行。

    并且我在本地使用 其他工具也都正常。情况是这样的画个表格吧。

    method http https
    快捷指令 GET
    快捷指令 POST
    浏览器 POST
    httpie POST

    我在本地用其他工具测试都一切正常 http post https://api.test.com/v2/caht message=123

    nginx 配置

            location /v2/ {
                proxy_pass http://127.0.0.1:8000;
                proxy_set_header Host api.openai.com;
                proxy_set_header X-Real-IP $remote_addr;
            }
    

    test server

    from flask import Flask, request
    app = Flask(__name__)
    
    @app.route('/v2/<path:path>', methods=['GET', 'POST'])
    def v2_path(path):
        if request.method == 'GET':
            print('--GET request headers:\n{}\n--end header--\n'.format(request.headers))
            return f'Path that matches /v2/* is: {path}'
        if request.method == 'POST':
            print('--POST request headers:\n{}\n--end header--\n'.format(request.headers))
            data = request.get_json()
            message = data.get('message')
            print('--POST request body:\nTYPE:{}\n{}\n--end body--\n'.format(type(data), data))
            return f'Path that matches /v2/* is: {path}\n{message}'
         
    if __name__ == '__main__':
        app.run(host="127.0.0.1", port=8000, debug=True)
    
    
    第 1 条附言  ·  2023-03-12 22:09:49 +08:00
    应该是快捷指令对 http2 支持的不够好吧。
    花了老鼻子劲了。
    把 nignix 配置 `listen 443 ssl http2;` 改成 `listen 443 ssl;`
    快捷指令就可以正常工作了。
    1 条回复    2023-03-25 20:00:45 +08:00
    xavierskip
        1
    xavierskip  
    OP
       2023-03-25 20:00:45 +08:00
    找到问题所在了,是 nginx 的问题,对于 Nginx 1.9.15~1.10.x ,这个问题将始终存在。

    [被 http2 坑了一把,nginx 1.9.15/1.10.0 + http2 + post + safari 有严重 bug](/t/300566)

    [谈谈 Nginx 的 HTTP/2 POST Bug]( https://imququ.com/post/nginx-http2-post-bug.html)

    我应该首先看一下错误的日志,当我把错误日志设置成 debug ,提示错误 `client sent stream with data before settings were acknowledged while processing HTTP/2 connection`.一搜就明白了。看来要去更新 nginx 了!
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3537 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 04:41 · PVG 12:41 · LAX 21:41 · JFK 00:41
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.