cURL / Mailing Lists / curl-library / Single Mail

curl-library

CURLINFO_REDIRECT_URL

From: <isaac_at_newcyberian.com>
Date: Fri, 25 Jul 2008 21:04:46 -0600 (MDT)

With the following codes I was trying to capture the supposedly redirected
url. But I got some garbage in the character string instead. What did I
do wrong? Thanks!

int main(int argc, char* argv[])
{
    string url;
    CURL *curl; // Our curl objects
    CURLcode result;
    curl = curl_easy_init(); // Create our curl handle
    if (curl)
    {
            // Now set up all of the curl options
            curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 0);
            curl_easy_setopt(curl, CURLOPT_HEADER, 0);
            curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writer);
            curl_easy_setopt(curl, CURLOPT_WRITEDATA, &buffer);
            url = "http://www.microsoft.com/BillGates/";
        curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
        buffer = "";
        result = curl_easy_perform(curl); // Attempt to retrieve the remote page
          char new_url[1024];
         curl_easy_getinfo(curl, CURLINFO_REDIRECT_URL, &new_url);
        if (result == CURLE_OK) // Did we succeed?
        {
                  cout << buffer << endl;
                  cout << "Redirected URL: " << &new_url << endl;
           }
           else
           {
                   cout << "Error occur " << result;
           }
    }
    curl_easy_cleanup(curl);
    return 0;
}
Received on 2008-07-26