Properly encoded parameters. Otherwise the query gets truncated.

This commit is contained in:
Juan Pablo 2013-09-24 04:02:14 -03:00
parent 3e1ecb4a84
commit 2999a8068a
3 changed files with 25 additions and 1 deletions

View file

@ -5,6 +5,28 @@
boost::asio::io_service HttpReq::io_service; boost::asio::io_service HttpReq::io_service;
std::string HttpReq::urlEncode(const std::string &s)
{
const std::string unreserved = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_.~";
std::string escaped="";
for(size_t i=0; i<s.length(); i++)
{
if (unreserved.find_first_of(s[i]) != std::string::npos)
{
escaped.push_back(s[i]);
}
else
{
escaped.append("%");
char buf[3];
sprintf(buf, "%.2X", s[i]);
escaped.append(buf);
}
}
return escaped;
}
HttpReq::HttpReq(const std::string& server, const std::string& path) HttpReq::HttpReq(const std::string& server, const std::string& path)
: mResolver(io_service), mSocket(io_service), mStatus(REQ_IN_PROGRESS) : mResolver(io_service), mSocket(io_service), mStatus(REQ_IN_PROGRESS)
{ {

View file

@ -47,6 +47,8 @@ public:
std::string getContent(); std::string getContent();
static std::string urlEncode(const std::string &s);
private: private:
static boost::asio::io_service io_service; static boost::asio::io_service io_service;

View file

@ -20,7 +20,7 @@ std::shared_ptr<HttpReq> GamesDBScraper::makeHttpReq(ScraperSearchParams params)
if(cleanName.empty()) if(cleanName.empty())
cleanName = params.game->getCleanName(); cleanName = params.game->getCleanName();
path += "name=" + cleanName; path += "name=" + HttpReq::urlEncode(cleanName);
//platform TODO, should use some params.system get method //platform TODO, should use some params.system get method
return std::make_shared<HttpReq>("thegamesdb.net", path); return std::make_shared<HttpReq>("thegamesdb.net", path);