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

2023-03-12 12:05:24 +08:00
 xavierskip

不是有利用 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)

757 次点击
所在节点    问与答
1 条回复
xavierskip
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 了!

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/923331

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX