curl - Uploading a file to http(s) server using POST request through libcurl in c -


i want upload file http server post request, using libcurl.

static int copy_to_http_server(char *src, char *disp_src, char srcflag,                                  char *dst, char *disp_dst, char dstflag) {   curl *curl;   curlcode res;   char *url = disp_dst;   char *outfilename = src;    struct curl_httppost *formpost=null;   struct curl_httppost *lastptr=null;   struct curl_slist *headerlist=null;   static const char buf[] = "expect:";    /* src = /users/play/team.jpg     * url = http://10.1.2.3/repo/team_server.jpg     * want 'src' copied under 'repo' directory on http server ,     * file name on server should team_server.jpg or team.jpg    * fine */    curl_global_init(curl_global_all);    /* fill in file upload field */   curl_formadd(&formpost,                &lastptr,                curlform_copyname, "sendfile",                curlform_file, src,                curlform_end);    /* fill in filename field */   curl_formadd(&formpost,                &lastptr,                curlform_copyname, "filename",                curlform_copycontents, src,                curlform_end);   /* fill in submit field too, if needed */   curl_formadd(&formpost,              &lastptr,              curlform_copyname, "submit",              curlform_copycontents, "send",              curlform_end);    curl = curl_easy_init();   /* initialize custom header list (stating expect: 100-continue     not      wanted */   if(curl) {     curl_easy_setopt(curl, curlopt_verbose, 1l);     /* url receives post */     curl_easy_setopt(curl, curlopt_url, url);     if (res != curle_ok) {        printf("could not set url : %s\n",curl_easy_strerror(res));     } else {       printf("able set\n");     }       curl_easy_setopt(curl, curlopt_followlocation, 1l);     curl_easy_setopt(curl, curlopt_protocols, curlproto_http | curlproto_https);     curl_easy_setopt(curl, curlopt_httppost, formpost);      /* perform request, res return code */         printf("calling curl_easy_perform\n");     res = curl_easy_perform(curl);     /* check errors */     if(res != curle_ok){       fprintf(stderr, "curl_easy_perform() failed: %s\n",               curl_easy_strerror(res));     }         printf("after calling curl_easy_perform\n");     /* cleanup */     curl_easy_cleanup(curl);      /* cleanup formpost chain */     curl_formfree(formpost);   }   curl_global_cleanup();   return 1; } 

below verbose output getting post response :-

> post /repo/proc.out http/1.1 host: 10.1.2.3 accept: */* content-length: 0 expect: 100-continue content-type: multipart/form-data; boundary=----------------------------8708d4558a12  < http/1.1 404 not found < date: sat, 28 may 2016 07:37:10 gmt * server apache/2.2.15 (centos) not blacklisted < server: apache/2.2.15 (centos) < content-length: 289 < connection: close < content-type: text/html; charset=iso-8859-1 <  <!doctype html public "-//ietf//dtd html 2.0//en"> <html><head> <title>404 not found</title> </head><body> <h1>not found</h1> <p>the requested url /repo/proc.out not found on server.</p> <hr> <address>apache/2.2.15 (centos) server @ 10.1.2.3 port 80</address> </body></html> * closing connection 0 

most amazing part not able upload file command line , , getting same error :- curl -f filedata=@myfile.txt http://10.1.2.3/repo

<!doctype html public "-//ietf//dtd html 2.0//en"> <html><head> <title>404 not found</title> </head><body> <h1>not found</h1> <p>the requested url /repo/ not found on server.</p> <hr> <address>apache/2.2.15 (centos) server @ 10.1.2.3 port 80</address> </body></html> 

but able download file same path i.e "http://10.1.2.3/repo/available_file.jpeg"

do need configure on http server or script/programm should running on server upload file server ?

could 1 please ?

you need cgi script process data @ /repo or /repo/proc.out

the cgi script should written in language supported web server environment.

the script read environment, , data sent script, process it, , send response curl script.

some web servers come default cgi script dump data you. might found in cgi-bin directory.


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -