Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URL encoding error #52

Open
GoogleCodeExporter opened this issue Mar 14, 2015 · 0 comments
Open

URL encoding error #52

GoogleCodeExporter opened this issue Mar 14, 2015 · 0 comments

Comments

@GoogleCodeExporter
Copy link

What steps will reproduce the problem?
1. Call twitCurl::search with a hashtag search string

What is the expected output? What do you see instead?

Expected output is the search results. Actual output is an authentication error.

What version of the product are you using? On what operating system?

r122 on Windows 8 x64

Please provide any additional information below.

oauth_signature needs to be generated with the unencoded URL which is done 
correctly, however the parameters then need to be encoded before being passed 
to cURL.

Here's what I've done to work around this and I can now search with hashtags:

std::vector<std::string> &split(const std::string &s, char delim, 
std::vector<std::string> &elems) {
    std::stringstream ss(s);
    std::string item("");
    while (std::getline(ss, item, delim)) {
        if (!item.empty())
            elems.push_back(item);
    }
    return elems;
}

bool twitCurl::performGet( const std::string& getUrl )

...

    std::string request("");
    /* Check for parameters */
    if (getUrl.find('?')!=std::string::npos)
    {
        std::size_t divide = getUrl.find_first_of('?')+1;
        std::string encodedparams("");
        std::string params=getUrl.substr(divide);
        std::vector<std::string> vparams;
        split(params,'&',vparams);
        for (unsigned int i=0;i<vparams.size();i++)
        {
            if (i>0) encodedparams+="&";
            std::size_t pos = vparams[i].find('=');
            if (pos!=std::string::npos)
                encodedparams+=vparams[i].substr(0,pos+1)+urlencode(vparams[i].substr(pos+1));
            else
                encodedparams+=vparams[i];
        }
        request=getUrl.substr(0,divide)+encodedparams;
    }
    else
        request=getUrl;

    /* Set http request and url */
    curl_easy_setopt( m_curlHandle, CURLOPT_HTTPGET, 1 );
    curl_easy_setopt( m_curlHandle, CURLOPT_URL, request.c_str() );

Original issue reported on code.google.com by sbd...@gmail.com on 18 Sep 2013 at 1:36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant