【问题标题】:HTTP POST request returns 400, SERVER_PORT_SECURE not usedHTTP POST 请求返回 400,未使用 SERVER_PORT_SECURE
【发布时间】:2017-01-09 12:01:06
【问题描述】:

我正在尝试从嵌入式设备向我的网络服务器发送 POST 请求,但网络服务器向我返回错误 400。

这是我发送到服务器 80 端口的请求:

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

然后我收到以下回复:

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:noreply@totaalholding.nl?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>

错误似乎提示主机名或请求uri错误,所以我也尝试了POST链接中的整个URL:

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

这也没有运气。我尝试过的其他事情

  • 不同的用户代理
  • HTTP/1.0
  • 主机标头中没有子域

所有这些似乎都导致相同的错误。

有人建议吗?我错过了标题吗?标题有错误吗?

非常感谢任何帮助或建议!

问候, 罗伯特

【问题讨论】:

  • 我看到请求没有Content-Length 标头。经过一些测试,Apache似乎不需要它,但尝试添加它。

标签: http http-post httprequest http-status-code-400 http-1.1


【解决方案1】:

对于那些寻找类似问题的人;问题是逗号显然不是帖子请求中的有效字符,对逗号进行urlencode,生活又好了:)

【讨论】:

    猜你喜欢
    • 2015-09-27
    • 1970-01-01
    • 2020-11-10
    • 1970-01-01
    • 2021-07-10
    • 2021-11-20
    • 1970-01-01
    • 2015-06-02
    • 1970-01-01
    相关资源
    最近更新 更多