diff options
author | ng0 <ng0@infotropique.org> | 2017-10-06 14:15:34 +0000 |
---|---|---|
committer | ng0 <ng0@infotropique.org> | 2017-10-06 14:15:34 +0000 |
commit | 64d20516fc61405cf0de4db0b0b8c52b3cafe917 (patch) | |
tree | 804233b6e02880b5774b9cc3a015ddaeb036717a /docs/examples/postit2.c | |
parent | dc3acc1603d57da12f54d5e360e40eda12b1066c (diff) | |
parent | 3ea76790571c1f7cf1bed34fabffd3cc20ad3dd3 (diff) | |
download | gnurl-64d20516fc61405cf0de4db0b0b8c52b3cafe917.tar.gz gnurl-64d20516fc61405cf0de4db0b0b8c52b3cafe917.tar.bz2 gnurl-64d20516fc61405cf0de4db0b0b8c52b3cafe917.zip |
Merge tag 'curl-7_56_0'
curl 7.56.0
Diffstat (limited to 'docs/examples/postit2.c')
-rw-r--r-- | docs/examples/postit2.c | 56 |
1 files changed, 26 insertions, 30 deletions
diff --git a/docs/examples/postit2.c b/docs/examples/postit2.c index b40743637..d357ecc2f 100644 --- a/docs/examples/postit2.c +++ b/docs/examples/postit2.c @@ -5,7 +5,7 @@ * | (__| |_| | _ <| |___ * \___|\___/|_| \_\_____| * - * Copyright (C) 1998 - 2016, Daniel Stenberg, <daniel@haxx.se>, et al. + * Copyright (C) 1998 - 2017, Daniel Stenberg, <daniel@haxx.se>, et al. * * This software is licensed as described in the file COPYING, which * you should have received as part of this distribution. The terms @@ -47,46 +47,42 @@ int main(int argc, char *argv[]) CURL *curl; CURLcode res; - struct curl_httppost *formpost=NULL; - struct curl_httppost *lastptr=NULL; - struct curl_slist *headerlist=NULL; + curl_mime *form = NULL; + curl_mimepart *field = NULL; + struct curl_slist *headerlist = NULL; static const char buf[] = "Expect:"; curl_global_init(CURL_GLOBAL_ALL); - /* Fill in the file upload field */ - curl_formadd(&formpost, - &lastptr, - CURLFORM_COPYNAME, "sendfile", - CURLFORM_FILE, "postit2.c", - CURLFORM_END); + curl = curl_easy_init(); + if(curl) { + /* Create the form */ + form = curl_mime_init(curl); - /* Fill in the filename field */ - curl_formadd(&formpost, - &lastptr, - CURLFORM_COPYNAME, "filename", - CURLFORM_COPYCONTENTS, "postit2.c", - CURLFORM_END); + /* Fill in the file upload field */ + field = curl_mime_addpart(form); + curl_mime_name(field, "sendfile"); + curl_mime_filedata(field, "postit2.c"); + /* Fill in the filename field */ + field = curl_mime_addpart(form); + curl_mime_name(field, "filename"); + curl_mime_data(field, "postit2.c", CURL_ZERO_TERMINATED); - /* Fill in the submit field too, even if this is rarely needed */ - curl_formadd(&formpost, - &lastptr, - CURLFORM_COPYNAME, "submit", - CURLFORM_COPYCONTENTS, "send", - CURLFORM_END); + /* Fill in the submit field too, even if this is rarely needed */ + field = curl_mime_addpart(form); + curl_mime_name(field, "submit"); + curl_mime_data(field, "send", CURL_ZERO_TERMINATED); - curl = curl_easy_init(); - /* initialize custom header list (stating that Expect: 100-continue is not - wanted */ - headerlist = curl_slist_append(headerlist, buf); - if(curl) { + /* initialize custom header list (stating that Expect: 100-continue is not + wanted */ + headerlist = curl_slist_append(headerlist, buf); /* what URL that receives this POST */ curl_easy_setopt(curl, CURLOPT_URL, "http://example.com/examplepost.cgi"); if((argc == 2) && (!strcmp(argv[1], "noexpectheader"))) /* only disable 100-continue header if explicitly requested */ curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headerlist); - curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost); + curl_easy_setopt(curl, CURLOPT_MIMEPOST, form); /* Perform the request, res will get the return code */ res = curl_easy_perform(curl); @@ -98,8 +94,8 @@ int main(int argc, char *argv[]) /* always cleanup */ curl_easy_cleanup(curl); - /* then cleanup the formpost chain */ - curl_formfree(formpost); + /* then cleanup the form */ + curl_mime_free(form); /* free slist */ curl_slist_free_all(headerlist); } |