cURL / Mailing Lists / curl-library / Single Mail

curl-library

problem with followlocation

From: Hetfield <hetfield_at_email.it>
Date: Thu, 27 Nov 2003 18:00:09 +0100

hi:
i'm writing a simple app that download a file.
it works good if there is no redirection. with redirection doesn't work.

can you tell me where's my fault? (i hope there isn't a libcurl bug!)
i get only header in my saved file:

screen prints:
http://ocbmaurice.dyndns.org/pl/slist.pl/server.met?download/server-max.met
* About to connect() to ocbmaurice.dyndns.org:80
* Connected to ocbmaurice.dyndns.org (62.2.175.50) port 80
> GET /pl/slist.pl/server.met?download/server-max.met HTTP/1.1
Host: ocbmaurice.dyndns.org
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*

* Closing connection #0
0
ok

and in file i get:
TTP/1.1 200 OK
Date: Thu, 27 Nov 2003 17:32:03 GMT
Server: Apache/1.3.27 (Unix) mod_gzip/1.3.19.1a mod_throttle/3.1.2
mod_perl/1.27
Connection: close
Transfer-Encoding: chunked
Content-Type: text/plain

this is WGET results...it follows redirection...as you can see a 302
code...

wget
http://ocbmaurice.dyndns.org/pl/slist.pl/server.met?download/server-max.met
--17:55:38--
http://ocbmaurice.dyndns.org/pl/slist.pl/server.met?download/server-max.met
           => `server.met?download%2Fserver-max.met'
Resolving ocbmaurice.dyndns.org... fatto.
Connecting to ocbmaurice.dyndns.org[62.2.175.50]:80... connected.
HTTP richiesta inviata, aspetto la risposta... 302 Found
Location: http://slist.no-ip.info/vinhcrftfa/max/server.met [segue]
--17:55:40-- http://slist.no-ip.info/vinhcrftfa/max/server.met
           => `server.met'
Resolving slist.no-ip.info... fatto.
Connecting to slist.no-ip.info[61.38.219.107]:80... connected.
HTTP richiesta inviata, aspetto la risposta... 200 OK
Lunghezza: 3,023 [text/plain]

100%[==================================================================>] 3,023 4.15K/s ETA 00:00

17:55:48 (4.15 KB/s) - `server.met' salvato [3023/3023]

*********************
MY CODE:
********************
#include <stdio.h>
#include <curl/curl.h>
#include <curl/types.h>
#include <curl/easy.h>

 int get(char *url)
 {
   CURL *curl_handle;
   FILE *outfile;
   printf("%s\n",url);

   curl_global_init(CURL_GLOBAL_ALL);
   //init a new curl session
   curl_handle = curl_easy_init();

   outfile = fopen("test.curl", "w");

   if (outfile!=NULL) {
   curl_easy_setopt(curl_handle, CURLOPT_URL, url);
   curl_easy_setopt( curl_handle, CURLOPT_HEADER, 1 );
   curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, TRUE);
   curl_easy_setopt(curl_handle, CURLOPT_MAXREDIRS , 10);
   curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION , 1);
   curl_easy_setopt(curl_handle, CURLOPT_FILE, outfile);
   curl_easy_perform(curl_handle);
   }
   else return 1;

   int a;
   /* cleanup curl stuff */
   curl_easy_getinfo(curl_handle,CURLINFO_REDIRECT_COUNT,&a);
   curl_easy_cleanup(curl_handle);
   printf("%d",a);

   return 0;
 }

 int main(int argc, char **argv)
 {

if (get(argv[1])==0) { printf("\nok\n"); return 0;}
else return 1;

 }

-------------------------------------------------------
This SF.net email is sponsored by: SF.net Giveback Program.
Does SourceForge.net help you be more productive? Does it
help you create better code? SHARE THE LOVE, and help us help
YOU! Click Here: http://sourceforge.net/donate/
Received on 2003-11-27