curl-library
Help - retriveal of header & body info
Date: Thu, 31 Dec 2009 17:11:27 +0530
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
-------------------------------------------------------------------
List admin: http://cool.haxx.se/list/listinfo/curl-library
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2009-12-31