Hi,
 I have removed the line and used the following lines of code with
libcurl version 7.19.7 on AIX 5.3 OS


        CURL *curl_handle;

      static const char *headerfilename = "head.out";

      FILE *headerfile;

      static const char *bodyfilename = "body.out";

      FILE *bodyfile;

 

      curl_global_init(CURL_GLOBAL_ALL);

       curl_handle = curl_easy_init();

 

      CURLcode retCode = CURLE_OK ;

      const char *pErrMsg = NULL;

      /* Setting Proxy*/

      retCode = curl_easy_setopt(curl_handle, CURLOPT_PROXY, "");

      /* set URL to get */ 

      retcode = curl_easy_setopt(curl_handle, CURLOPT_URL,
"http://m.in.yahoo.com/?p=us";);      


      /* no progress meter please */ 

      retCode = curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);

      
      /* open the files */ 

      //headerfile = fopen(headerfilename,"w");

      headerfile = fopen("/homes/head.out","w");

      if (headerfile == NULL) 

      {

            curl_easy_cleanup(curl_handle);

            return -1;

      }

      bodyfile = fopen("/homes/ body.out","w");

      if (bodyfile == NULL) 

      {

            curl_easy_cleanup(curl_handle);

            return -1;  }

 

      /* we want the headers to this file handle */ 

      retCode = curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER,
headerfile);


      retCode = curl_easy_setopt(curl_handle,    CURLOPT_WRITEDATA,
(FILE*)bodyfile);


      /* get it! */ 

      retCode = curl_easy_perform(curl_handle);

      /* close the header file */ 

      fclose(headerfile);

 

      /* cleanup curl stuff */ 

      curl_easy_cleanup(curl_handle);


Still I am not getting the information in body.out file.

I could see that the stream is getting retrieved inside write_data
function but its not written to the file.

size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream) {
  char* cptr = (char*)ptr;
  cout << cptr << endl;
  cout << cptr << endl;
  int written = fwrite(ptr, size, nmemb, (FILE *)stream);
  return written;
}

Please let me know if you can give me some inputs why this information
is not getting written into the file stream in UNIX.
 

Br
Sasikanth
----------------------------------------------------------------------

Message: 1
Date: Thu, 31 Dec 2009 17:11:27 +0530
From: "Arunachalam, Sasikanth"
        <[email protected]>
To: <[email protected]>
Subject: Help -  retriveal of header & body info
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset="us-ascii"

Hi,

      I am using libcurl version 7.19.7 . I have tried the following
piece of code to retrieve the header & body information of the a website
with Mozila firebox 5.0 in AIX 5.3 OS

 

      CURL *curl_handle;

      static const char *headerfilename = "head.out";

      FILE *headerfile;

      static const char *bodyfilename = "body.out";

      FILE *bodyfile;

 

      curl_global_init(CURL_GLOBAL_ALL);

 

      /* init the curl session */ 

      curl_handle = curl_easy_init();

 

      CURLcode retCode = CURLE_OK ;

      const char *pErrMsg = NULL;

      /* Setting Proxy*/

      retCode = curl_easy_setopt(curl_handle, CURLOPT_PROXY, "");

      

      pErrMsg =  curl_easy_strerror(retCode);

      

      /* set URL to get */ 

      retcode = curl_easy_setopt(curl_handle, CURLOPT_URL,
"http://m.in.yahoo.com/?p=us";);      

      pErrMsg =  curl_easy_strerror(retCode);

      

      /* no progress meter please */ 

      retCode = curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 1L);

 

      pErrMsg =  curl_easy_strerror(retCode);

      

      /* send all data to this function  */ 

      retCode =curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
write_data);

      

      pErrMsg =  curl_easy_strerror(retCode);

      

      /* open the files */ 

      //headerfile = fopen(headerfilename,"w");

      headerfile = fopen("/homes/head.out","w");

      if (headerfile == NULL) 

      {

            curl_easy_cleanup(curl_handle);

            return -1;

      }

      bodyfile = fopen("/homes/ body.out","w");

      if (bodyfile == NULL) 

      {

            curl_easy_cleanup(curl_handle);

            return -1;  }

 

      /* we want the headers to this file handle */ 

      retCode = curl_easy_setopt(curl_handle,   CURLOPT_WRITEHEADER,
headerfile);

 

      pErrMsg =  curl_easy_strerror(retCode);

      

      /*

      * Notice here that if you want the actual data sent anywhere else
but

      * stdout, you should consider using the CURLOPT_WRITEDATA option.
*/ 

 

 

      retCode = curl_easy_setopt(curl_handle,    CURLOPT_WRITEDATA,
bodyfile);

      pErrMsg =  curl_easy_strerror(retCode);

      

 

      /* get it! */ 

      retCode = curl_easy_perform(curl_handle);

 

      pErrMsg =  curl_easy_strerror(retCode);

      

      /* close the header file */ 

      fclose(headerfile);

 

      /* cleanup curl stuff */ 

      curl_easy_cleanup(curl_handle);

 

I am not able to retrieve the header & body information using the above
piece of code. I didn't get any error message using CURLcode.

 

I got the content of head.out as 

 

HTTP/1.1 200 OK

content-language: en-US

content-type: text/html;charset=ISO-8859-1

date: Thu, 31 Dec 2009 11:27:15 GMT

p3p: CP="NON CUR OTPi OUR NOR UNI"

server: IBM_HTTP_Server

x-old-content-length: 1041

transfer-encoding: chunked

cache-control: no-cache

pragma: no-cache

expires: Thu, 01 Jan 1970 00:00:00 GMT

Set-Cookie: AMWEBJCT!%2FAppl!JSESSIONID=0000XIgzYlq7yx3qKdAUaCxtfWN:-1;
Path=/

Set-Cookie: PD_STATEFUL_a705f792-72e2-11db-b0e3-000629c30555=%2FAppl;
Path=/

 

& the  empty information in body.out file.

 

On the other hand, I have performed the same operation in Windows with
Internet explorer and I am able to retrieve the header and body
information without any issues.

 

Request you to please let me know whether  I need to set any specific
settings for my Unix development.

 

Br

Sasikanth

-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://cool.haxx.se/pipermail/curl-library/attachments/20091231/f3424d8
7/attachment.htm>

------------------------------

Message: 2
Date: Thu, 31 Dec 2009 13:26:18 +0100
From: Julien Chaffraix <[email protected]>
To: libcurl development <[email protected]>
Subject: Re: Help - retriveal of header & body info
Message-ID:
        <[email protected]>
Content-Type: text/plain; charset=windows-1252

Hi,

> ????? retCode =curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION,
> write_data);

You are overriding the default write function here.

> I am not able to retrieve the header & body information using the
above
> piece of code. I didn?t get any error message using CURLcode.
>
> I got the content of head.out as

[snipped the header information]

> & the? empty information in body.out file.

Do you get something in body.out if you remove the above line in your
code?

Best regards,
Julien


------------------------------

_______________________________________________
curl-library mailing list
[email protected]
http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-library


End of curl-library Digest, Vol 52, Issue 59
********************************************
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette:  http://curl.haxx.se/mail/etiquette.html

Reply via email to