cURL / Mailing Lists / curl-users / Single Mail

curl-users

RV:

From: Cristina Gil <cristina.gil_at_sumenor.com>
Date: Tue, 12 Aug 2008 11:45:01 +0200

Hi,
 
Im programming an application that will send a http request (GET) to a server. The server response with a stream which contains all the data?? I don’t know if Im doing something wrong sending the request with curl or it’s the read of the stream correct..
 
Help me, please…
 
My program:
 
#include <stdio.h>
#include <stdint.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <unistd.h>
#include <curl/curl.h>
#include <errno.h>

int main(){
  CURL *curl;
  char *url; //10
  char *stream;
  char *s;

  FILE *fd;
  char *file;

  url="http://192.168.0.63/cgi-axis/admin/serverreport.cgi";

  /* get a curl handle */
  curl = curl_easy_init();
 
  if(curl) {
     /* specify target URL, and note that this URL should also include a file
        name, not only a directory (as you can do with GTP uploads) */
    curl_easy_setopt(curl,CURLOPT_URL, url);
 
    /* tell libcurl we can use "basic" auth */

    curl_easy_setopt(curl, CURLOPT_HTTPAUTH, (long)CURLAUTH_BASIC);

    /* set user name and password for the authentication */
    curl_easy_setopt(curl, CURLOPT_USERPWD, "user:pass");

    curl_easy_setopt(curl,CURLOPT_HTTPGET, (long)stream);
    if (CURLE_OK==0){printf("OK\n");}

   fd=fmemopen(stream,sizeof(stream),"r+");
     
    if (fd==NULL){
        printf("error\n");
    perror("error");}
    else{
        printf("fmemopen OK\n");
    
               int i;
               i=fgets(s,100,fd);
              printf("FIRST fgets %d \n",i); // I wanna read (is an empty line) the first line of the stream but it returns a huge number 12xxxxx so I think it returns all the stream again
               i=fgets(s,100,fd);
               printf("SECOND fgets %d \n", i); // this line is supposed to have data but i=0 so… no data

               if (s!=NULL){
                        printf("%s",s); // it looks like a stream… �� when it was supposed to be a string…
               }
 
      }
   }
   /* always cleanup */
    curl_easy_cleanup(curl);

   fclose(fd);

   return 0;
}
 
Thanks!!!!!!!!!

AVISO LEGAL
La Informacion incluida en el presente correo electronico es SECRETO PROFESIONAL Y CONFIDENCIAL, siendo para el uso exclusivo del destinatario arriba mencionado. Si usted lee este mensaje y no es el destinatario señalado, el empleado o el agente responsable de entregar el mensaje al destinatario, o ha recibido esta comunicacion por error, le informamos que esta totalmente prohibida cualquier divulgacion, distribucion o reproduccion de esta comunicacion, y le rogamos que nos lo notifique inmediatamente y nos devuelva el mensaje original a la direccion arriba mencionada. Gracias.

-------------------------------------------------------------------
List admin: http://cool.haxx.se/cgi-bin/mailman/listinfo/curl-users
FAQ: http://curl.haxx.se/docs/faq.html
Etiquette: http://curl.haxx.se/mail/etiquette.html
Received on 2008-08-12