cURL / Mailing Lists / curl-library / Single Mail

curl-library

Cookies on one domain and posting to another

From: Niall Twomey <twomers_at_gmail.com>
Date: Tue, 8 Feb 2011 14:50:28 +0000

Hi all,

I have a program that monitors the state of a web page, and parses values
from it. Now, an option within the program is for the data that's parsed to
be stored on an online database, and it is when I attempt to do this that I
encounter problems.

I log onto the first website (so need to maintain cookies) and the second
website doesn't require cookies at all. So after parsing the values from the
html, I simply post to the second website. However, it is when I attempt to
parse new values from the first website after posting to the second that I
encounter problems--the program crashes (with no indication about where the
crash came from).

Is there something I need to be aware of for maintaining cookies on one site
while posting to another? The crash report is completely uninformative.

The source-code getter function is here:
  source.clear();
  curl_easy_setopt( curl, CURLOPT_URL, URL.c_str() );
  if ( parameters.size() )
    curl_easy_setopt( curl, CURLOPT_POSTFIELDS, parameters.c_str() );
  curl_easy_setopt( curl, CURLOPT_COOKIEFILE, "" );
  curl_easy_setopt( curl, CURLOPT_SSL_VERIFYPEER, 0 );
  curl_easy_setopt( curl, CURLOPT_SSL_VERIFYHOST, 0 );

  clearMemory();

  curl_easy_setopt( curl, CURLOPT_WRITEFUNCTION, curlWriter ); // Gather
source callback
  curl_easy_setopt( curl, CURLOPT_WRITEDATA, (void*)&chunk ); // Save it to
stop automatic printing

  res = curl_easy_perform( curl );

  if ( res != CURLE_OK )
    return false;

  if ( chunk.size )
    source = chunk.memory;

  curl_easy_getinfo( curl, CURLINFO_COOKIELIST, &c );

And the posting method is here (postType is a
std::map<std::string,std::string> associative container, which associates
the form parameter name (when looping through iter->first) with the value
(iter->second))
  source.clear();
  // The post parameters
  curl_httppost *formpost = NULL;
  curl_httppost *lastptr = NULL;

  // Iterator for the map
  postType::const_iterator it = postParams.begin();

  // Loop over the range of post parameters
  while ( it != postParams.end() ) {
    curl_formadd( &formpost,
                  &lastptr,
                  CURLFORM_COPYNAME, it->first.c_str(),
                  CURLFORM_PTRCONTENTS, it->second.c_str(),
                  CURLFORM_END );

    it ++;
  }

  // And post. Wohoo.
  setURL( pURL );
  curl_easy_setopt( curl, CURLOPT_URL, pURL.c_str() );
  curl_easy_setopt( curl, CURLOPT_HTTPPOST, formpost );
  res = curl_easy_perform( curl );
  curl_formfree( formpost );

Am I missing something here? Please advise,

Regards,

Niall

-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2011-02-08