502 Bad Gateway after POST request method

Dear All,
I am currently using an Arduino based Wifi module to make a POST request to a web service implemented by Caddy.
The POST is successful but I am receiving the following response …

HTTP/1.1 502 Bad Gateway
Content-Type: text/plain; charset=utf-8
Server: Caddy
X-Content-Type-Options: nosniff
Date: Tue, 30 May 2017 14:07:50 GMT

On the other hand when I am using Curl (https://curl.haxx.se/) I am receiving the following response …

< HTTP/1.1 200 OK
< Content-Type: text/html;charset=utf-8
< Date: Tue, 30 May 2017 13:55:50 GMT
< Server: Jetty(9.4.4.v20170414)

Since the POST is successful could you please advise of a possible reason of the “502 Bad Gateway” response?

Best,
George

It seems your curl request is a direct post to your Jetty-based service. Can you try the same POST, but to Caddy instead?

Hello,
Thank you for you reply.
I forgot to mention that sometimes the POST from the Wifi module gets reply 200. I just tried it and after 502 I got 200 …

//-------------------------------------------------------------
connecting…
Data length: 11
HTTP/1.1 502 Bad Gateway
Content-Type: text/plain; charset=utf-8
Server: Caddy
X-Content-Type-Options: nosniff
Date: Wed, 31 May 2017 07:07:14 GMT
Content-Length: 16
Connection: close

502 Bad Gateway
connecting…
Data length: 11
HTTP/1.1 200 OK
Content-Length: 7
Content-Type: text/plain
Date: Wed, 31 May 2017 07:07:15 GMT
Server: Jetty(9.4.4.v20170414)
Connection: close

Success
//-------------------------------------------------------------

Best,
George

I’m a little confused on where exactly your results are coming from. If you could let us know the full curl commands you’re using, including what you’re connecting to, and your Caddyfile, that would go a long way to clarifying the situation.

Hello,
Thank you very much for your reply.
A colleague helped me to find out the error.
The error was that I was sending two more bytes than the size of data defined at the "Content-Length: " .
Best,
George

1 Like

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.