mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-12-29 03:40:55 +00:00
Fixed: Use correct formatted HTTP 1.1 query, previous one was blocked by some security software (a big thanks to Vojtech Vobr from AVG Technologies for his investigation to help us to fix this issue)
This commit is contained in:
parent
60257c3bf1
commit
768fa69b6b
1 changed files with 46 additions and 8 deletions
|
@ -98,27 +98,56 @@ bool CHttpClient::send(const std::string& buffer, bool verbose)
|
|||
// ***************************************************************************
|
||||
bool CHttpClient::sendRequest(const std::string& methodWB, const std::string &url, const std::string &cookieName, const std::string &cookieValue, const std::string& postParams, bool verbose)
|
||||
{
|
||||
// Remove the host from the URL
|
||||
string path;
|
||||
std::string path, host;
|
||||
|
||||
// Remove the protocol from the URL
|
||||
if (url.substr(0, 7) == "http://")
|
||||
path = url.substr(7);
|
||||
else
|
||||
path = url;
|
||||
path = path.substr(path.find( "/" ));
|
||||
|
||||
std::string::size_type pos = path.find("/");
|
||||
|
||||
// Remove the host from the URL
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
host = path.substr(0, pos);
|
||||
path = path.substr(pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
host = path;
|
||||
path.clear();
|
||||
}
|
||||
|
||||
// build HTTP request
|
||||
std::string request;
|
||||
request += methodWB + " " + path + " HTTP/1.1\r\n";
|
||||
request += "Host: " + host + "\r\n";
|
||||
|
||||
// Send
|
||||
if (cookieName.empty() && postParams.empty())
|
||||
{
|
||||
return send(methodWB + path + "\r\n", verbose);
|
||||
request += "\r\n";
|
||||
|
||||
return send(request, verbose);
|
||||
}
|
||||
else
|
||||
{
|
||||
string cookieStr, postStr;
|
||||
if (!cookieName.empty())
|
||||
cookieStr = "Cookie: " + cookieName + "=" + cookieValue + "\r\n";
|
||||
request += "Cookie: " + cookieName + "=" + cookieValue + "\r\n";
|
||||
|
||||
if (!postParams.empty())
|
||||
postStr = "Content-Type: application/x-www-form-urlencoded\r\nContent-Length: " + toString(postParams.size()) + "\r\n\r\n" + postParams;
|
||||
return send(methodWB + path + " HTTP/1.0\r\n" + cookieStr + postStr + "\r\n", verbose);
|
||||
{
|
||||
request += "Content-Type: application/x-www-form-urlencoded\r\n";
|
||||
request += "Content-Length: " + toString(postParams.size()) + "\r\n";
|
||||
request += "\r\n";
|
||||
request += postParams;
|
||||
}
|
||||
|
||||
request += "\r\n";
|
||||
|
||||
return send(request, verbose);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -179,6 +208,15 @@ bool CHttpClient::receive(string &res, bool verbose)
|
|||
}
|
||||
}
|
||||
//nlinfo("all received '%s'", res.c_str());
|
||||
|
||||
// only keep content (delimited by two \r\n) and discard server headers
|
||||
std::string::size_type pos = res.find("\r\n\r\n");
|
||||
|
||||
if (pos != std::string::npos)
|
||||
{
|
||||
res = res.substr(pos + 4);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue