Winsock 400 Bad Request, openresty
2019-6-22 21:53:48
收藏:0
阅读:306
评论:1
我有一个软件的身份验证系统,我向服务器发送GET请求以验证它,然后回显true或false。每当我使用Winsock发送HTTP请求时,我会收到错误:400错误请求并且下面是openresty。任何帮助都将受到赞赏!
#define _WIN32_WINNT 0x0400
#include <iostream>
#include <locale>
#include <sstream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <windows.h>
#include <winsock2.h>
#pragma comment(lib, "ws2_32.lib")
using namespace std;
void main() {
WSADATA wsaData;
SOCKET Socket;
SOCKADDR_IN SockAddr;
int lineCount = 0;
int rowCount = 0;
struct hostent* host;
locale local;
char buffer[10000];
int i = 0;
int nDataLength;
string website_HTML;
// website url
string url = "www.mysitewebsite.com/auth/auth.php?hwid=" + hwidPro +
"&username=" + Username + "&password=" + Password;
// HTTP GET
string get_http =
"GET / HTTP/1.1\r\nHost: " + url + "\r\nConnection: close\r\n\r\n";
if(WSAStartup(MAKEWORD(2, 2), &wsaData) != 0) {
cout << "WSAStartup failed.\n";
system("pause");
// return 1;
}
Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
host = gethostbyname("www.mysite.com");
SockAddr.sin_port = htons(80);
SockAddr.sin_family = AF_INET;
SockAddr.sin_addr.s_addr = *((unsigned long*)host->h_addr);
if(connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) {
cout << "Could not connect";
system("pause");
// return 1;
}
// send GET / HTTP
send(Socket, get_http.c_str(), strlen(get_http.c_str()), 0);
// recieve html
while((nDataLength = recv(Socket, buffer, 10000, 0)) > 0) {
int i = 0;
while(buffer[i] >= 32 || buffer[i] == '\n' || buffer[i] == '\r') {
website_HTML += buffer[i];
i += 1;
}
}
closesocket(Socket);
WSACleanup();
const char* result = website_HTML.c_str();
Log::Msg(result);
if(website_HTML == "true") {
authsucsess();
} else {
Log::Fatal(result);
Log::Fatal("无效的登录或HWID");
exit(0);
}
}
我已编辑我的帖子,让它成为一个最小的、可复现的例子。希望它更好 修改2:我已添加HTTP响应:
HTTP/1.1 400 Bad Request
Date: Sat, 22 Jun 2019 21:33:11 GMT
Content-type: text/html
content-length: 170
connection: close
Server: awex
X-Xss Protection: 1; mode=block
X-Content-Type-Options: nosniff
X-Request-ID: 7ccdf09347f06d7a061ad41aa45d5af7
<html>
<head><title>400 Bad Request</title></head>
<body bgcolor="white">
<center><h1>400 Bad Request</h1></center>
<hr><center>openresty</center>
</body>
</html>
点赞
评论区的留言会收到邮件通知哦~
推荐文章
- Lua 虚拟机加密load(string.dump(function)) 后执行失败问题如何解决
- 我想创建一个 Nginx 规则,禁止访问
- 如何将两个不同的lua文件合成一个 东西有点长 大佬请耐心看完 我是小白研究几天了都没搞定
- 如何在roblox studio中1:1导入真实世界的地形?
- 求解,lua_resume的第二次调用继续执行协程问题。
- 【上海普陀区】内向猫网络招募【Skynet游戏框架Lua后端程序员】
- SF爱好求教:如何用lua实现游戏内调用数据库函数实现账号密码注册?
- Lua实现网站后台开发
- LUA错误显式返回,社区常见的规约是怎么样的
- lua5.3下载库失败
- 请问如何实现文本框内容和某个网页搜索框内容连接,并把网页输出来的结果反馈到另外一个文本框上
- lua lanes多线程使用
- 一个kv数据库
- openresty 有没有比较轻量的 docker 镜像
- 想问一下,有大佬用过luacurl吗
- 在Lua执行过程中使用Load函数出现问题
- 为什么 neovim 里没有显示一些特殊字符?
- Lua比较两个表的值(不考虑键的顺序)
- 有个lua简单的项目,外包,有意者加微信 liuheng600456详谈,最好在成都
- 如何在 Visual Studio 2022 中运行 Lua 代码?

你的
GET请求格式不正确,这是你当前发送的请求:GET / HTTP/1.1 Host: www.mysitewebsite.com/auth/auth.php?hwid=[...]&username=[...]&password=[...] Connection: close应该是这样的:
GET /auth/auth.php?hwid=[...]&username=[...]&password=[...] HTTP/1.1 Host: www.mysitewebsite.com Connection: close尝试使用以下代码:
string s_host = "www.mysitewebsite.com"; string s_resource = "/auth/auth.php"; string s_query = "?hwid=" + hwidPro + "&username=" + Username + "&password=" + Password; string url = s_host + s_resource + s_query; string get_http = "GET " + s_resource + s_query + " HTTP/1.1\r\n" "Host: " + s_host + "\r\n" "Connection: close\r\n" "\r\n"; ... host = gethostbyname(s_host.c_str()); ... send(Socket, get_http.c_str(), get_http.size(), 0); ... while((nDataLength = recv(Socket, buffer, sizeof(buffer), 0)) > 0) { website_HTML.append(buffer, nDataLength); } ...