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
9571f5f235
commit
e22fa8b951
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)
|
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
|
std::string path, host;
|
||||||
string path;
|
|
||||||
|
// Remove the protocol from the URL
|
||||||
if (url.substr(0, 7) == "http://")
|
if (url.substr(0, 7) == "http://")
|
||||||
path = url.substr(7);
|
path = url.substr(7);
|
||||||
else
|
else
|
||||||
path = url;
|
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
|
// Send
|
||||||
if (cookieName.empty() && postParams.empty())
|
if (cookieName.empty() && postParams.empty())
|
||||||
{
|
{
|
||||||
return send(methodWB + path + "\r\n", verbose);
|
request += "\r\n";
|
||||||
|
|
||||||
|
return send(request, verbose);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
string cookieStr, postStr;
|
|
||||||
if (!cookieName.empty())
|
if (!cookieName.empty())
|
||||||
cookieStr = "Cookie: " + cookieName + "=" + cookieValue + "\r\n";
|
request += "Cookie: " + cookieName + "=" + cookieValue + "\r\n";
|
||||||
|
|
||||||
if (!postParams.empty())
|
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());
|
//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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue