我正在尝试连接到000webhost.com托管的网站,但我对c ++和socket非常新,所以我不明白我是如何做到这一点的。这就是我所拥有的:
SOCKET Socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
SOCKADDR_IN SockAddr;
SockAddr.sin_port = htons(80);
SockAddr.sin_family = AF_INET;
cout << "Checking for updates... Please wait";
struct hostent *hEnt;
SockAddr.sin_addr.s_addr = inet_addr("23.23.251.76");
if (connect(Socket, (SOCKADDR*)(&SockAddr), sizeof(SockAddr)) != 0) {
MessageBox::Show("Could not connect to server.", "Error",MessageBoxButtons::OK, MessageBoxIcon::Exclamation);
system("pause");
}
string FullBuffer = "";
string VersionText = std::to_string(8+version.length());
string Header = string("POST /VersionChecker.php HTTP/1.1\r\nHost: MyWebsite.000webhostapp.com\r\nContent-Type: application/x-www-form-urlencoded\r\nContent-Length: " + VersionText + string("\r\nConnection: keep-alive\r\n\r\nVersion=") + version);
cout << Header;
地址&#34; 23.23.251.76&#34;是000webhostapp.com的IP。使用此代码,获取错误&#34; 404 Not Found&#34;。任何帮助将不胜感激!
答案 0 :(得分:0)
这个错误主要是它在锡上说的:您能够连接到服务器,但找不到您请求的资源(/VersionChecker.php
)。
很难肯定地说,但我相信你应该首先考虑的是IP是否正确,因为它已被硬编码而不是用DNS查找。值得注意的是,我们无法保证MyWebsite.000webhostapp.com
与000webhostapp.com
位于同一地址,您的问题内容就是这样。