cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Help: getting the current url

From: Am Ro <skyelabs_at_gmail.com>
Date: Thu, 10 Apr 2008 17:22:41 -0400

On Apr 10, 2008, at 4:34 PM, Joe Nardone wrote:

>> int connect(const char* aURL)
>> {
>> const char *currentUrl;
>> CURL *urlHandler;
>> curl_easy_setopt(urlHandle, CURLOPT_URL, aURL);
>> curl_easy_perform(urlHandle);
>>
>>
>> if (aUrl == currentUrl)
>> {
>> connect(aURL);
>> }
>> else
>> {
>> printf(currentURL);
>> }
>> }
>
> You never assign currentURL. Why would you ever expect it to contain
> useful data?
>
> It's been troubling on this list lately the number of people who don't
> need help with CURL, but with the basics of writing code.
>
> Joe

That was a typo in my message. I used curl_easy_getinfo, but it
prints "\270", instead of the value of currentURL.

New Code:

        int connect (const char* aURL)
        {
                char *currentURL;
                CURL *urlHandler;
                curl_easy_setopt(urlHandle, CURLOPT_URL, aURL);
                curl_easy_perform(urlHandle);
                curl_easy_getinfo(urlHandle, CURLINFO_EFFECTIVE_URL, currentURL);
                printf ((const char*)currentURL);
        }

                
Received on 2008-04-10