Post data to http server using libcurl

Raj rajani.vemula at gmail.com
Thu Nov 9 07:08:42 EST 2006


Hi,
I am newbie to programming with libcurl. the problem is i want to send
my gmail username and password outside the browser and get access to my
mail. this i am doing with LibCurl. Though i dont get any errors, i am
nt able to get the o/p Can anyone kindly help. i will attach the
program here
#include <curl/curl.h>
 #include <curl/types.h>
 #include <curl/easy.h>

 int main(int argc, char *argv[])
 {
   CURL *curl;
   CURLcode res;

   struct curl_httppost *formpost=NULL;
   struct curl_httppost *lastptr=NULL;
   struct curl_slist *headerlist=NULL;
   char buf[] = "Expect:";

   curl_global_init(CURL_GLOBAL_ALL);

   /* Fill in the file upload field */
   curl_formadd(&formpost,
              &lastptr,
                CURLFORM_COPYNAME, "rajani.vemula",
                CURLFORM_END);

   /* Fill in the filename field */
   curl_formadd(&formpost,
                &lastptr,
                CURLFORM_COPYNAME, "xxxxx",
                CURLFORM_END);
   curl_formadd(&formpost,
                &lastptr,
                CURLFORM_COPYNAME, "null",
                CURLFORM_COPYCONTENTS, "Sign in",
                CURLFORM_END);




   curl = curl_easy_init();
   /* initalize custom header list (stating that Expect: 100-continue
is
 not
      wanted */
   headerlist = curl_slist_append(headerlist, buf);
   if(curl) {
     /* what URL that receives this POST */
     curl_easy_setopt(curl, CURLOPT_URL,"
http://mail.google.com/mail");
     curl_easy_setopt(curl, CURLOPT_PROXY, "proxyname");
   curl_easy_setopt(curl, CURLOPT_PROXYUSERPWD, "User:Password)";
       /* only disable 100-continue header if explicitly requested */
       curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist);
     curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);
     res = curl_easy_perform(curl);

     /* always cleanup */
     curl_easy_cleanup(curl);

     /* then cleanup the formpost chain */
     curl_formfree(formpost);
      curl_slist_free_all(headerlist
  }
   return 0;
 }

Thanks




More information about the Python-list mailing list