|
|
|
@ -22,7 +22,7 @@ WSADATA wsaData;
@@ -22,7 +22,7 @@ WSADATA wsaData;
|
|
|
|
|
int iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u, const std::string &hostName, const std::string &doc) { |
|
|
|
|
HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u, const std::string &doc) { |
|
|
|
|
#ifdef WIN32 |
|
|
|
|
if (iResult != 0) { |
|
|
|
|
std::cout << "WSAStartup failed: " << iResult << std::endl; |
|
|
|
@ -33,20 +33,20 @@ HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u, const std::string &hostNa
@@ -33,20 +33,20 @@ HTTPRequest::HTTPRequest(const std::shared_ptr<URI> u, const std::string &hostNa
|
|
|
|
|
document = doc; |
|
|
|
|
version = Version::HTTP10; |
|
|
|
|
method = Method::GET; |
|
|
|
|
host = hostName; |
|
|
|
|
userAgent = "NetRunner"; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
bool HTTPRequest::sendRequest(std::function<void(const HTTPResponse&)> responseCallback) const { |
|
|
|
|
struct addrinfo hints; |
|
|
|
|
struct addrinfo *serverInfo = nullptr; |
|
|
|
|
std::string host = uri->authority.host; |
|
|
|
|
memset(&hints, 0, sizeof(hints)); |
|
|
|
|
hints.ai_family = AF_UNSPEC; |
|
|
|
|
hints.ai_socktype = SOCK_STREAM; |
|
|
|
|
hints.ai_flags = AI_PASSIVE; |
|
|
|
|
const int res = getaddrinfo(host.c_str(), "80", &hints, &serverInfo); |
|
|
|
|
const int res = getaddrinfo(uri->authority.host.c_str(), std::to_string(uri->authority.port).c_str(), &hints, &serverInfo); |
|
|
|
|
if (res != 0) { |
|
|
|
|
std::cout << "Could not lookup " << host << ": " << res << std::endl; |
|
|
|
|
std::cout << "Could not lookup " << uri->authority.host << ": " << res << std::endl; |
|
|
|
|
freeaddrinfo(serverInfo); |
|
|
|
|
return false; |
|
|
|
|
} |
|
|
|
|