Parse Error: The server returned a malformed response - Error: Parse Error: Expected HTTP/ - when trying to access one of my app URLs with postman

Parse Error: The server returned a malformed response - Error: Parse Error: Expected HTTP/ - when trying to access one of my app URLs with postman

我正在管理一个由 python 中的第三方构建的应用程序。

我有这个 url 调度程序

urls += [(r'/path/objectA/(.*)', ObjectAHandler)]  # this was made by third parts, it is expected to work

和这个class

class ObjectAHandler(BaseHandler):

    def __init__(self, application, request, **kwargs):
        super(ObjectAHandler, self).__init__(application, request, **kwargs)  # do the init of the basehandler

    @gen.coroutine
    def post(self, action=''):
        response = {}
        
            ...     
            
            response = yield self.my_method(json_data)
        
            ... 

        self.write(json.dumps(response))

    def my_method(self, json_data)
        ...

我想检查应用程序是否正确接收到请求和return一些响应。

所以我尝试使用 Postman

访问 url

请求类型:

POST

URL:

http://<machine_ip>:<machine_port>/path/objectA/

我从 Postman 响应框收到此错误

Parse Error: The server returned a malformed response

当我点击“在控制台中查看”时,我看到了

POST http://machine_ip>:<machine_port>/path/objectA/
Error: Parse Error: Expected HTTP/
Request Headers
Content-Type: application/json
User-Agent: PostmanRuntime/7.28.4
Accept: */*
Postman-Token: d644d7dd-699b-4d77-b32f-46a575ae31fc
Host: 10.133.5.37:22
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Request Body

Error: Parse Error: Expected HTTP/ 是什么意思?

我检查了我的应用程序日志,但它似乎没有处理任何请求,即使 Postman 指示服务器正在 return 发送(格式错误的)响应。

我还尝试将目标 url 更改为:

https...

但是 returns

 Error: write EPROTO 28427890592840:error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER:../../third_party/boringssl/src/ssl/tls_record.cc:242:

我发现了

然后我也试了:

http://<machine_ip>/path/objectA/

<machine_ip>/path/objectA/

一般来说 return:

Error: connect ECONNREFUSED <machine_ip>:80

我也试过换行

urls += [(r'/path/objectA/(.*)', ObjectAHandler)]  

urls += [(r'/path/objectA/', ObjectAHandler)]  

urls += [(r'/path/objectA', ObjectAHandler)]  

但其中 none 个有效。

怎么了?我该如何解决?

更新

显然,根据 Postman this thread Github,问题只发生在 Postman Desktop 而不是浏览器上的 Postman。

所以我尝试在我的浏览器上发送请求表单 Postman,但我收到了

 Cloud Agent Error: Can not send requests to reserved address. Make sure address is publicly accessible or select a different agent.

因为,根据 this other thread

Postman Website cannot send a request to your computer's localhost. It first needs to connect to your PC with the Postman desktop client

即使我遵循该答案中的指示

Run it [ndr. Postman desktop], then go to the Postman workspace in your browser -> send the request and it will work.

我还是一样

Error: Parse Error: Expected HTTP/

在 Postman Desktop 和 Postman on browser 上。

更新

继续调试,我尝试从我的终端向 URL 投射 curl:

myuser@mymachine-VirtualBox:~$ curl --verbose "http://<target_machine_ip>:<target_machine_port>/path/objectA"

我得到了:

*   Trying <target_machine_ip>:<target_machine_port>...
* Connected to <target_machine_ip> (<target_machine_ip>) port <target_machine_port> (#0)
> GET /orkpos5/receipt HTTP/1.1
> Host: <target_machine_ip>:<target_machine_port>    
> User-Agent: curl/7.74.0    
> Accept: */*    
>     
* Received HTTP/0.9 when not allowed  
    
* Closing connection 0    
curl: (1) Received HTTP/0.9 when not allowed

已解决

由于暴露的api是第三方构建供内部使用的,所以没有暴露给public。

我不知道,所以在请求中 URL 我输入了 HTTP 请求的众所周知的端口号,数字 22(参见 list of well-known port numbers.)。

为了解决这个问题,在请求URL中,我把<target_machine_port>改成了api实际暴露的端口