C++ Schannel POST 400 错误代码错误请求
C++ Schannel POST 400 Error Code Bad Request
由于某种原因,我不知道 POST 请求不起作用。我很确定问题出在 POST 字符串"POST /profile.php HTTP/1.1rnid=2323rnContent-Length: rnrn"
.GET 请求工作正常,但 POST 请求无法正常工作。
我使用 TLS VER 443 通过端口 1.0 连接到服务器
这是我从服务器获得的错误代码。编辑:我正在尝试编辑这篇文章来修复它,它告诉我我的帖子主要是代码,但我希望不再是代码。
85 bytes of data sent
HTTP/1.1 400 Bad Request
Content-Type: text/html; charset=utf-8
Date: Fri, 22 Nov 2019 06:56:20 GMT
Connection: close
Content-Length: 2959
<!DOCTYPE html>
<html lang="en" id="facebook">
<head>
<title>Facebook | Error</title>
<meta charset="utf-8">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="cache-control" content="no-store">
<meta http-equiv="cache-control" content="max-age=0">
<meta http-equiv="expires" content="-1">
<meta http-equiv="pragma" content="no-cache">
<meta name="robots" content="noindex,nofollow">
<style>
html, body {
color: #141823;
background-color: #e9eaed;
font-family: Helvetica, Lucida Grande, Arial,
Tahoma, Verdana, sans-serif;
margin: 0;
padding: 0;
text-align: center;
}
#header {
height: 30px;
padding-bottom: 10px;
padding-top: 10px;
text-align: center;
}
#icon {
width: 30px;
}
h1 {
font-size: 18px;
}
p {
font-size: 13px;
}
#footer {
border-top: 1px solid #ddd;
color: #9197a3;
font-size: 12px;
padding: 5px 8px 6px 0;
}
</style>
</head>
<body>
<div id="header">
<a href="//www.facebook.com/">
<img id="icon" src="//static.facebook.com/images/logos/facebook_2x.png" />
</a>
</div>
<div id="core">
<h1 id="sorry">Sorry, something went wrong.</h1>
<p id="promise">
We're working on it and we'll get it fixed as soon as we can.
</p>
<p id="back-link">
<a id="back" href="//www.facebook.com/">Go Back</a>
</p>
<div id="footer">
Facebook
<span id="copyright">
© 2019
</span>
<span id="help-link">
·
<a id="help" href="//www.facebook.com/help/">Help Center</a>
</span>
</div>
</div>
<script>
document.getElementById('back').onclick = function() {
if (history.length > 1) {
history.back();
return false;
}
};
// Adjust the display based on the window size
if (window.innerHeight < 80 || window.innerWidth < 80) {
// Blank if window is too small
document.body.style.display = 'none';
};
if (window.innerWidth < 200 || window.innerHeight < 150) {
document.getElementById('back-link').style.display = 'none';
document.getElementById('help-link').style.display = 'none';
};
if (window.innerWidth < 200) {
document.getElementById('sorry').style.fontSize = '16px';
};
if (window.innerWidth < 150) {
document.getElementById('promise').style.display = 'none';
};
if (window.innerHeight < 150) {
document.getElementById('sorry').style.margin = '4px 0 0 0';
document.getElementById('sorry').style.fontSize = '14px';
document.getElementById('promise').style.display = 'none';
};
</script>
</body>
</html>
3215 bytes received
与其发出 POST 请求,不如使用 GET 请求并执行此操作
"GET /profile.php?id=2323 HTTP/1.1rnConnection: closernrn"
这主要取决于您要连接的服务器,因此如果这不起作用,请尝试使用 HTTP v1.0
"GET /profile.php?id=2323 HTTP/1.0rnConnection: closernrn"
如果这仍然不起作用,您可能需要指定主机,主要是当您尝试从看起来像https://en30.picwebsite.com
的网站获取图像时
"GET /profile.php?id=2323 HTTP/1.1rnHost: en30.picwebsite.comrnConnection: closernrn"
尝试 HTTP v1.0 和 v1.1
如果所有操作都不起作用,请确保使用SSL/TLS进行连接(如果它是一个安全的网站(。如果是,请尝试主页简单的GET请求"GET / HTTP/1.1rnConnection: closernrn"
HTTP v1.0和v1.1
如果这也不起作用,那么啊哈,这可能是您的套接字/TLS实现或服务器的问题。
编辑:
我终于想出了如何发出正确的 POST 请求。您必须始终在 POST 请求中指定内容长度,例如,内容长度应该是查询的大小 -"std::string("id=2323&file=funpic&name=rosh").size()
并且查询必须位于请求字符串的末尾,在我的情况下是Connection: closernrn
例如,我之前想要将id更改为2323/profile.php?id=2323
的查询,id执行此操作 -
std::string query = "id=2323";
std::string request = "POST /profile.php HTTP/1.1rnContent-Length: " +
std::to_string(query.size()) + "rnConnection: closernrn" + query;
send(sock, request.c_str(), request.size(), 0);
您也可以在查询后添加rn
,它仍然可以id=2323rn
确保仅在完整请求之后添加查询,因为查询应该在网站内容中而不是在标题中。
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 错误:请求从"常量字符 [5]"转换为非标量类型"字符串"
- 为什么我收到来自谷歌的错误请求?
- 获取"rw_ssid"中成员"长度"的错误请求,该成员属于非类类型"char*"
- 从谷歌日历API获取错误请求
- 错误:请求成员 .. 是非类类型"char"
- C++ Schannel POST 400 错误代码错误请求
- Winsock 400 错误请求,开放性
- 错误:请求从 std::chrono::time_point 浮点数转换为非标量类型长整型
- 错误:请求从“ void”转换为“ QString”的非量表类型
- 错误请求,您的浏览器发送了此服务器无法理解的请求 - Qt Websocket 服务器
- 如何在beast::websocket中读取错误请求的标头
- 使用 winsock 库发送 GET HTTP 请求时出现 400 错误请求错误
- Waht [错误] 请求 memebr 'area' 在非类类型 'float' 中'r'是什么意思?
- C++:成员'的错误请求;Foo'在'f',其是非类类型'Foo*'
- 错误:请求“y”中的成员“x”,该成员属于非类类型“class**”
- 非类类型 'char' 的成员 getName 的错误请求
- HTTP 400 错误请求
- 错误:请求非类类型的成员
- 成员"查找"的错误请求