Thread Rating:
  • 445 Vote(s) - 2.59 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Problemm with separating header and data using curl
12-12-2011, 03:32 PM,
#1
Problemm with separating header and data using curl
Hi,

This is Khushi, i'm trying with a sample code to get header separately into a file for continous streaming urls. but am not to get it.. both the header and data information are present in the body.out file.
I'm pasting my sample code here..

##

FILE *bodyfile;
FILE *headerfile;

CURL *curl_handle;
int responsebytes_written = 0;
static size_t write_data(void *ptr, size_t size, size_t nmemb, void *stream)
{
responsebytes_written = fwrite(ptr, size, nmemb, (FILE *)stream);
printf("bytes written %d\n", responsebytes_written);
return responsebytes_written;
}

static size_t write_header(void *ptr, size_t size, size_t nmemb, void *stream)
{
int written = fwrite(ptr, size, nmemb, (FILE *)stream);
printf("bytes written in header %d\n", written);
return written;
}

static size_t progressfun(void *ptr, size_t size, size_t nmemb, void *stream)
{
CURL *curl_handle1;
int ret = 0;
static int progresscnt = 0;
int written = fwrite(ptr, size, nmemb, (FILE *)stream);


//if(responsebytes_written == 0)
{
progresscnt++;
}
/* else
{
responsebytes_written = 0;
}*/
printf("progress fun %d %d\n", written, progresscnt);
#if 0
if(progresscnt == 10)
{

printf("Interface has gone down!!!!!!!!!!!!!!!!!!\n");

#if 1
// curl_easy_cleanup(curl_handle);
curl_handle1 = curl_easy_init();
curl_easy_setopt(curl_handle1, CURLOPT_VERBOSE, 1);
curl_easy_setopt(curl_handle1, CURLOPT_INTERFACE, "em1");
//curl_easy_setopt(curl_handle1, CURLOPT_FRESH_CONNECT, "eth0");
printf("handle is %d\n", curl_handle);
curl_easy_setopt(curl_handle1, CURLOPT_URL,"http://www.google.co.in");


//curl_easy_setopt(curl_handle1, CURLOPT_URL,"http://scfire-dtc-aa03.stream.aol.com:80/stream/1010");
curl_easy_setopt(curl_handle1,CURLOPT_WRITEHEADER, headerfile);

/* we want the headers to this file handle */
curl_easy_setopt(curl_handle1, CURLOPT_HEADERFUNCTION, write_header);
curl_easy_setopt(curl_handle1, CURLOPT_WRITEDATA, bodyfile);
/* send all data to this function */
curl_easy_setopt(curl_handle1, CURLOPT_WRITEFUNCTION, write_data);
#if 1
curl_easy_setopt(curl_handle1, CURLOPT_PROXY, "proxy.tcs.com:8080");
curl_easy_setopt(curl_handle1, CURLOPT_PROXYUSERNAME , "522528");
curl_easy_setopt(curl_handle1, CURLOPT_PROXYPASSWORD , "Ggupsp@2911");
#endif


curl_easy_setopt(curl_handle1, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl_handle1, CURLOPT_PROGRESSFUNCTION, progressfun);
printf("before easy perform handle1\n");
ret = curl_easy_perform(curl_handle1);
printf("after easy perform handle1 %d\n", ret);
#endif
progresscnt = 31;
}
#endif
return written;
}
//curl_sockopt_callback fsockcb;
int fsockcb (void *clientp,curl_socket_t curlfd,curlsocktype purpose)
{
int ret =0 ;
printf("socket id is %d\n", curlfd);
if(ret = setsockopt(curlfd, SOL_SOCKET, SO_BINDTODEVICE,
"em1", (curl_socklen_t)(strlen(("em1")+1))) != 0) {
// error = SOCKERRNO;
}
printf("am hereeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee %d\n", errno);
return 0;
}

int main(void)
{

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

static const char *bodyfilename = "body.out";
int ret = 0;

/* open the files */
headerfile = fopen(headerfilename,"w");
if (headerfile == NULL) {
// curl_easy_cleanup(curl_handle);
printf("headerfile open failed\n");
return -1;
}
bodyfile = fopen(bodyfilename,"w");
if (bodyfile == NULL) {
// curl_easy_cleanup(curl_handle);
printf("bodyfile open failed\n");
return -1;
}


curl_global_init(CURL_GLOBAL_ALL);

/* init the curl session */
curl_handle = curl_easy_init();

/* set URL to get */

curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);
//curl_easy_setopt(curl_handle, CURLOPT_INTERFACE, "em1");
// curl_easy_setopt(curl_handle, CURLOPT_INTERFACE, "172.19.94.192");
// curl_easy_setopt(curl_handle, CURLOPT_SOCKOPTFUNCTION,&fsockcb);

//curl_easy_setopt(curl_handle, CURLOPT_URL,"74.125.236.81");
curl_easy_setopt(curl_handle, CURLOPT_URL,"http://91.121.155.39:80");

// curl_easy_setopt(curl_handle, CURLOPT_NOSIGNAL,0);
// curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT,35);


/* no progress meter please */

curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(curl_handle, CURLOPT_PROGRESSFUNCTION, progressfun);
curl_easy_setopt(curl_handle, CURLOPT_WRITEHEADER, headerfile);

/* we want the headers to this file handle */
curl_easy_setopt(curl_handle, CURLOPT_HEADERFUNCTION, write_header);


curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, bodyfile);
/* send all data to this function */
curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, write_data);
#if 1
//curl_easy_setopt(curl_handle, CURLOPT_PROXY, "proxy.tcs.com:8080");
curl_easy_setopt(curl_handle, CURLOPT_PROXY, "172.19.193.33:8080");

curl_easy_setopt(curl_handle, CURLOPT_PROXYUSERNAME , "INDIA\\522528");
curl_easy_setopt(curl_handle, CURLOPT_PROXYPASSWORD , "Ggupsp@2911");
#endif

/*
* Notice here that if you want the actual data sent anywhere else but
* stdout, you should consider using the CURLOPT_WRITEDATA option. */

/* get it! */

printf("before main easy perform\n");
ret = curl_easy_perform(curl_handle);

printf("after main easy perform %d %d\n", ret, errno);
/* close the header file */
fclose(headerfile);
fclose(bodyfile);

/* cleanup curl stuff */
curl_easy_cleanup(curl_handle);

return 0;
}

Please do go through and help me in finding a solutions..thanks in advance...
waiting for responses..
Reply


Messages In This Thread
Problemm with separating header and data using curl - by Khushi - 12-12-2011, 03:32 PM

Possibly Related Threads...
Thread Author Replies Views Last Post
  Curl execute Oracle database procedure NamDH 3 4,054 04-21-2017, 03:40 PM
Last Post: tdeng
  Print data NamDH 5 4,615 04-04-2017, 02:27 PM
Last Post: dyoshida
  TLS通信下でCould not deserialize the object from Curl.発生 MIT 3 4,767 03-10-2017, 08:35 AM
Last Post: MIT
  Protecting SSL private key in a Curl script aensys 1 2,363 02-10-2017, 02:02 PM
Last Post: heavybugtracker
  curl library 7.36.0: curl_easy_perform() function call failed when used for getting a joezhao 1 3,632 10-19-2016, 09:41 AM
Last Post: dyoshida
  Curl IDE からのランチャが見つかりません umemura 1 3,771 06-30-2016, 10:12 AM
Last Post: umemura
  Curl RTE Install smtit 1 2,738 05-06-2016, 12:36 PM
Last Post: dice256
  Curl RTE Command line smtit 1 2,917 04-19-2016, 09:35 AM
Last Post: dice256
  What OS that CURL can support for deloyment? tiennv 1 4,574 08-22-2015, 02:12 AM
Last Post: tdeng
  Curl RTEのPPAPIプラグインについて でり 1 4,398 06-09-2015, 11:03 AM
Last Post: でり
Forum Jump:


Users browsing this thread:
1 Guest(s)

MyBB SQL Error

MyBB has experienced an internal SQL error and cannot continue.

SQL Error:
1017 - Can't find file: 'mybb_threadviews' (errno: 2)
Query:
INSERT INTO mybb_threadviews (tid) VALUES('372')