cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Object Moved/Location cut-off ?

From: Morph <morph_at_akbearsden.com>
Date: Mon, 24 Jun 2002 22:34:52 -0400

It looks like everything works now. Here's what I ended up using:

void get_url()
{
        extern struct plugin_struct *plug_args;

        // If url is empty, fail!
        if(plug_args->url[0]=='\0') {
                return_state(FALSE, plug_args);
                return;
        }
 
        // If the HTML buffer is full, clear it.
        if(plug_args->html_buff!=(char *)NULL) {
                memset(plug_args->html_buff,0,sizeof(*plug_args->html_buff));
                free(plug_args->html_buff);
                plug_args->html_buff = (char *)NULL;
                plug_args->buff_size = 0;
        }
 
        // Get a curl handle
        plug_args->curl_handle = curl_easy_init();
 
        // I changed this so that it adds the post data into the URL,
        // thanks to Daniel Stenberg for pointing out my error.
        // I just misunderstood how the GET worked, from reading the docs.
        if(plug_args->post_data[0]!='\0') {
                strcat(plug_args->url,"?");
                strcat(plug_args->url,plug_args->post_data);
        }

        // Add the URL
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_URL, plug_args->url);
 
        // Add my function to read the data response from curl
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_WRITEFUNCTION, html2buff);
 
        // Don't pass anything else to my function
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_FILE, (void *)NULL);
 
        // Added this to keep the cookies between handles.
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_COOKIEJAR, "mycookies.fil");
 
        // Tell curl where to look for stored cookies.
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_COOKIEFILE, "mycookies.fil");
 
        // Thanks to Daniel Stenberg again, for telling me about this little jewl.
        // This allows curl to automaticly follow "Location:" redirects.
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_FOLLOWLOCATION, TRUE);
 
        // Debug stuff
 #ifdef DEBUG
 
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_VERBOSE, TRUE);
 
        curl_easy_setopt(plug_args->curl_handle, CURLOPT_HEADER, TRUE);

#endif
 
        // Perform the curl operation
        curl_easy_perform(plug_args->curl_handle);
 
        curl_easy_cleanup(plug_args->curl_handle);
 
        plug_args->curl_handle = (CURL *)NULL;
 
        return_state(TRUE, plug_args);
        return;
}

Thank you very much for your help.

Sincerely,

Morph

-------------------------------------------------------
Sponsored by:
ThinkGeek at http://www.ThinkGeek.com/
Received on 2002-06-25