douying9296 2019-03-01 07:44
浏览 39
已采纳

Heroku H18错误,而我的后端对路由器响应200(多部分/表单数据)

I have an error when deploying my golang API on Heroku. Heroku detects a disconnect and report a 500 error, while in the logs my server correctly answer with a 200. It is multipart/form-data request with a file attached, and I simply return a JSON in the response body.

2019-03-01T07:35:29.060814+00:00 app[web.1]: xx.x.xx.x - - [01/Mar/2019:07:35:29 +0000] "POST /v1/fixture/extract/ HTTP/1.1" 200 2133
2019-03-01T07:35:29.413179+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/v1/fixture/extract/" host=xxx.com request_id=28cdf569-2e00-47b8-9989-9280865707c8 fwd="xx.x.xx.x" dyno=web.1 connect=1ms service=352ms status=503 bytes=2280 protocol=https

Here is the curl when I hit the service locally without reverse proxy:

*   Trying ::1...
* TCP_NODELAY set
* Connected to localhost (::1) port 8080 (#0)
> POST /v1/fixture/extract/ HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.64.0
> accept: application/json
> Content-Length: 154090
> Content-Type: multipart/form-data; boundary=------------------------7a9bb5de3838f429
> Expect: 100-continue
> 
< HTTP/1.1 200 OK
< Content-Type: application/json
< Date: Fri, 01 Mar 2019 07:44:50 GMT
< Connection: close
< Transfer-Encoding: chunked
< 

I struggle finding the reason while it would happen.

My go function:

func FixtureExtract(w http.ResponseWriter, r *http.Request) {
    w.Header().Set("Content-Type", "application/json")

    json.NewEncoder(w).Encode(ExtractFixture{})
}
  • 写回答

1条回答 默认 最新

  • douzhenzu0247 2019-03-01 08:03
    关注

    The cause of the error was that I was not consuming the multipart/form-data send by the client before returning an answer.

    This fixed the issue:

    func FixtureExtract(w http.ResponseWriter, r *http.Request) {
        w.Header().Set("Content-Type", "application/json")
    
        r.ParseMultipartForm(32 << 20)
    
        json.NewEncoder(w).Encode(ExtractFixture{})
    }
    

    I just had to parse the form with r.ParseMultipartForm(32 << 20).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥15 统计大规模图中的完全子图问题
  • ¥15 使用LM2596制作降压电路,一个能运行,一个不能
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错
  • ¥20 @microsoft/fetch-event-source 流式响应问题
  • ¥15 ogg dd trandata 报错
  • ¥15 高缺失率数据如何选择填充方式