curl-library
Problem with HTTP file upload using libcurl
Date: Mon, 17 Nov 2003 15:30:10 +0530
Hi list ,
I want to upload a file to Apache 2.0.46 server with Tomcat 4.1.24 as
servlet container using libcurl APIs. I am using HTTP protocol for this and
Windows 2000 OS.
But from output ,it seems that servlet is not being invoked.
I am able to upload file and process it from servlet when PUT request is
generated by cURL EXE. It works fine with curl.exe.
My libcurl program is as follows -
#include <stdio.h>
#include <fcntl.h>
#include <sys/stat.h>
#include <curl/curl.h>
int main(int argc, char **argv)
{
CURL *curl;
CURLcode res;
CURLcode response;
FILE * hd_src ;
int hd ;
struct stat file_info;
char *file;
char *url;
file= "D:\\curl\\fsddoc.txt";
url="http://localhost:8080/put/abcd1.dop ";
/* get the file size of the local file */
hd = open(file, O_RDONLY) ;
fstat(hd, &file_info);
close(hd) ;
hd_src = fopen(file, "rb");
if (hd_src == NULL)
printf ("Unable to open file");
/* In windows, this will init the winsock stuff */
curl_global_init(CURL_GLOBAL_ALL);
/* get a curl handle */
curl = curl_easy_init();
if(curl) {
printf("After easy init () \n");
/* enable uploading */
curl_easy_setopt(curl, CURLOPT_UPLOAD, TRUE) ;
/* enable verbose */
curl_easy_setopt(curl, CURLOPT_VERBOSE ,1);
/* HTTP PUT please */
curl_easy_setopt(curl, CURLOPT_PUT, TRUE);
printf("After setopt PUT\n");
/* specify target */
curl_easy_setopt(curl,CURLOPT_URL, url);
printf("After setopt URL \n%s",url);
printf("\n");
/* now specify which file to upload */
curl_easy_setopt(curl, CURLOPT_INFILE, hd_src);
/* and give the size of the upload (optional) */
curl_easy_setopt(curl, CURLOPT_INFILESIZE, file_info.st_size);
// Set values of cookies to be sent to ASP side.
curl_easy_setopt(curl,CURLOPT_COOKIE
,"fileName=file;uploadDir=D:/upoadedfile" );
/* Now run off and do what you've been told! */
printf("\n Before easy perform ()");
response = curl_easy_perform(curl);
printf("After easy perform \n ");
printf("CURLCODE := %d \n",respnose);
/* always cleanup */
curl_easy_cleanup(curl);
}
fclose(hd_src); /* close the local file */
printf("After closing local file ");
curl_global_cleanup();
return 0;
}
The OUTPUT of above Program is -
Running
After easy init ()
After setopt PUT
After setopt URL
http://localhost/put/abcd1.dop
Before easy perform ()
* About to connect() to localhost:80
* Connected to siddharth1.clearcase.mentorix.com (127.0.0.1) port 80
> PUT /put/abcd1.dop HTTP/1.1
Host: localhost
Pragma: no-cache
Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, */*
Transfer-Encoding: chunked
After this it terminates. It is not returning from curl_easy_perform(curl).
So what may be problem here ? Am I missing anything ?
Regards,
Pravin.
-------------------------------------------------------
This SF. Net email is sponsored by: GoToMyPC
GoToMyPC is the fast, easy and secure way to access your computer from
any Web browser or wireless device. Click here to Try it Free!
https://www.gotomypc.com/tr/OSDN/AW/Q4_2003/t/g22lp?Target=mm/g22lp.tmpl
Received on 2003-11-17