HTTP POST request returns 400, SERVER_PORT_SECURE not used

1.5k views Asked by At

I am attempting to send a POST request from an embedded device to my webserver, yet the webserver returns error 400 to me.

This is the request I am sending to port 80 of my server:

POST /api_back.php HTTP/1.1
Host: mysubdomain.mydomain.com
User-Agent: AppleWebKit/531.21.10
Accept: */*
Content-Type: application/x-www-form-urlencoded
Cache-Control: no-cache
Accept-Charset: utf-8, us-ascii
Pragma: no-cache

data=10,1,1,1,1,-48%0D%0A10,1,1,1,1,-48%0D%0A10,1,1,1,1,-47%0D%0A10,1,1,1,1,-48%0D%0A10,1,1,1,1,-48%0D%0A10,1,1,1,1,-47%0D%0A10,1,1,1,1,-47%0D%0A

Then I get the following reply:

http/1.1 400 bad request
date: sun, 08 jan 2017 16:59:54 gmt
server: apache/2.4.23 (unix) openssl/1.0.1e-fips mod_bwlimited/1.4
accept-ranges: bytes
connection: close
content-type: text/html



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
  <head>
    <title>400 Bad Request</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <style type="text/css">
        body {
         font-family: Verdana, Arial, Helvetica, sans-serif;
         font-size: 12px;
         background-color:#367E8E;
         scrollbar-base-color: #005B70;
         scrollbar-arrow-color: #F3960B;
         scrollbar-DarkShadow-Color: #000000;
         color: #FFFFFF;
   margin:0;
        }
        a { color:#021f25; text-decoration:none}
        h1 {
         font-size: 18px;
         color: #FB9802;
         padding-bottom: 10px;
         background-image: url(sys_cpanel/images/bottombody.jpg);
         background-repeat: repeat-x;
         padding:5px 0 10px 15px;
   margin:0;
        }
        #body-content p {
         padding-left: 25px;
         padding-right: 25px;
         line-height: 18px;
         padding-top: 5px;
         padding-bottom: 5px;
        }
        h2 {
         font-size: 14px;
         font-weight: bold;
         color: #FF9900;
         padding-left: 15px;
        }
    </style>
  </head>
  <body>
    <div id="body-content">  
<!-- start content-->

<!-- 
 instead of REQUEST_URI, we could show absolute URL via:
 http://HTTP_HOST/REQUEST_URI
    but what if its https:// or other protocol?
    
    SERVER_PORT_SECURE doesn't seem to be used
    SERVER_PORT logic would break if they use alternate ports
-->

<h1>400 Bad Request</h1>
<p>Your browser sent a request that this server could not understand:</p>
  <blockquote>
    (none) (port 80)
  </blockquote> 
<p>
    Please forward this error screen to 31.186.174.155's 
    <a href="mailto:[email protected]?subject=Error message [400] 400 Bad Request for (none) port 80 on Sunday, 08-Jan-2017 17:59:54 CET">
    WebMaster</a>.
</p>
<hr />


<!-- end content -->
    </div>
  </body>
</html>

The error seems to suggest the host name or request uri is wrong, so I also tried the whole URL in the POST link this:

POST http://mysubdomain.mydomain.com/api_back.php HTTP/1.1
Host: mysubdomain.mydomain.com
...

No luck with this either. Other things I tried

  • Different user agents
  • HTTP/1.0
  • No subdomain in host header

All of them seem to result in the same error.

Anyone a suggestion? Am I missing a header? Is there an error in the headers?

Any help or suggestions are much appreciated!

Regards, Robert

1

There are 1 answers

0
RMS95 On

For those of you looking for a similar issue; the problem was that a comma apparently is not a valid character in a post request, urlencode the comma and life's all good again :)