Crash on curl_easy_perform() when uploading a file on CURL in C++ -


i'm having issue crash when uploading file via curl library in c++. i'm using exact demo code location: https://curl.haxx.se/libcurl/c/fileupload.html

the thing change in code upload location, upload local wamp server on windows, , file upload, i've verified opening ok.

i'm running through visual studio 2014, , building curl through dll

the output program is:

*   trying 127.0.0.1... * tcp_nodelay set * connected 127.0.0.1 (127.0.0.1) port 80 (#0) > put /replayupload.php http/1.1 host: 127.0.0.1 accept: */* content-length: 43 expect: 100-continue  < http/1.1 100 continue 

*then crash @ line 66 in program. seems line:

 res = curl_easy_perform(curl); 

is causing problem invalid parameter. have verified curl variable not null, i'm finding difficult more debug info that, call stack references memory address within dll.

i'm able run demo upload post variables , page, runs fine without crash. crash occurs when uploading file.

my exact code is:

int main(void) {     curl *curl;     curlcode res;     struct stat file_info;     double speed_upload, total_time;     file *fd;      fd = fopen("e:\\testfiles\\test.txt", "rb"); /* open file upload */     if (!fd)         return 1; /* can't continue */                /* file size */     if (fstat(_fileno(fd), &file_info) != 0)         return 1; /* can't continue */      curl = curl_easy_init();     if (curl) {         /* upload place */         curl_easy_setopt(curl, curlopt_url,             "http://127.0.0.1/testupload.php");          /* tell "upload" url */         curl_easy_setopt(curl, curlopt_upload, 1l);          /* set read (on windows need use readfunction too) */         curl_easy_setopt(curl, curlopt_readdata, fd);          /* , give size of upload (optional) */         curl_easy_setopt(curl, curlopt_infilesize_large,             (curl_off_t)file_info.st_size);          /* enable verbose easier tracing */         curl_easy_setopt(curl, curlopt_verbose, 1l);          res = curl_easy_perform(curl);         /* check errors */         if (res != curle_ok) {             fprintf(stderr, "curl_easy_perform() failed: %s\n",                 curl_easy_strerror(res));          }         else {             /* extract transfer info */             curl_easy_getinfo(curl, curlinfo_speed_upload, &speed_upload);             curl_easy_getinfo(curl, curlinfo_total_time, &total_time);             fprintf(stderr, "speed: %.3f bytes/sec during %.3f seconds\n",                 speed_upload, total_time);          }         /* cleanup */         curl_easy_cleanup(curl);     }     fclose(fd);     return 0; } 

thanks tkausl spotting line

/* set read (on windows need use readfunction too) */ 

i added line code

curl_easy_setopt(curl, curlopt_readfunction, &fread); 

and seems work.


Comments

Popular posts from this blog

resizing Telegram inline keyboard -

command line - How can a Python program background itself? -

php - "cURL error 28: Resolving timed out" on Wordpress on Azure App Service on Linux -