12-12-2011, 03:32 PM,
|
|||||
|
|||||
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.. |
|||||
12-12-2011, 04:10 PM,
|
|||||
|
|||||
RE: Problemm with separating header and data using curl
I think you're probably looking for help with libcurl, which is occasionally confused with the language / runtime environment Curl.
Perhaps try: http://curl.haxx.se/ |
|||||
12-12-2011, 09:22 PM,
|
|||||
|
|||||
RE: Problemm with separating header and data using curl
Thanks for the reply.. can u tell me few other solutions so that i can try with that too..
(12-12-2011, 04:10 PM)c-s Wrote: I think you're probably looking for help with libcurl, which is occasionally confused with the language / runtime environment Curl. |
|||||
12-13-2011, 10:37 AM,
|
|||||
|
|||||
RE: Problemm with separating header and data using curl
Sorry if there is some continuing confusion, but I meant you should probably try asking at forums or lists for the actual software. This forum is for an entirely unrelated product (though it's certainly possible that some of our visitors also use cURL too!).
There's a mailing list for libcurl users at: http://curl.haxx.se/mail/list.cgi?list=curl-library |
|||||
« Next Oldest | Next Newest »
|
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: でり |
Users browsing this thread:
1 Guest(s)
1 Guest(s)