Sorry to drag this message thread on so long, I just have one more thing.. I've been trying to use formadd, but I must be doing something wrong. If I try: curl_formadd(&formPost, &last, CURLFORM_COPYNAME, "metadata", CURLFORM_COPYCONTENTS, jpost, CURLFORM_CONTENTLEN, 0, CURLFORM_CONTENTTYPE, "application/json" ,CURLFORM_END); then the header for multipart/form-data at the top disappears, and the content length becomes 0. The corresponding response states there to be a missing content header, and disconnects. Am I doing something wrong within the formadd? I assume the CURLFORM_COPYNAME is for changing the name just after the content disposition header, and that charset will be modified automatically, since I can't tell a way to do this explicitly. Headers for the beginning of the message were set as I have before with CURLOPT_HTTPHEADER with a slist of headers.
I can get the server to accept the message's header and boundary terms when building the all of the post data myself, but whatever string reader is being used server-side seems to have a problem with the formatting I have used. I'll ask on their forums what is wrong there, as I am sure that question is too application specific for this mailing list. I really appreciate the help, thank you. On Tue, Apr 4, 2017 at 4:18 PM, Daniel Stenberg <[email protected]> wrote: > On Tue, 4 Apr 2017, Reese Grimsley wrote: > > So since I am going to be using the same host, it will use the same >> physical connection, and it will be able to send multiple independent >> transfer? >> > > As I already answered this I'm not sure what else I'm going to reply when > you ask again without adding any more specific details to the question to > help me give a more specific answer. So: yes, maybe. > > I am confused on how to format a multipart POST request. I notice that >> when I set the content-type to multipart/form-data, it includes its own >> (randomly generated?) boundary term. >> > > It does, yes. But you're also setting that content-type header in vein > since libcurl will set that itself for multipart formposts. > > Can this boundary term by easily changed? >> > > No, it can't be changed at all actually, if you want to use libcurl's > formposting functions. > > If you think you need to set that string yourself you need to construct > the entire post "manually" and not use libcurl's formposting functions and > instead just send a normal "raw" posted crafted as you see fit, with the > boundary strings, separators, headers and all. > > My main question though is how to set the fields that look to be very >> similar to headers underneath the --"boundary" line, and then include the >> actual message data below that. >> > > They're not only similar to headers, they *are* headers. Each individual > section in a multipart post has its own set of headers. With libcurl you > set your headers with curl_formadd()'s CURLFORM_CONTENTHEADER option. > > Should these fields be defined by some setopt function, or are they a part >> of the message? >> > > libcurl will set a few when you use curl_formadd() so that each section > becomes a valid and working part as defined in the spec, but you can extend > that set if you want others there. > > It is supposed to look like what I have included in the last few lines of >> this message. >> > > The Content-Disposition: is automatically set by libcurl (as you can see > when you check what libcurl sends in a formpost) and the Content-Type: > header is set for a few files (based on the extension) but you can also set > that with CURLFORM_CONTENTTYPE. > > Following these "headers" (are they considered headers, or is there a >> better terminology?) would be a JSON formatted string of data, followed by >> a --boundary-- line. >> > > That data is the contents: CURLFORM_COPYCONTENTS. > > All this is explained and there's an example, in the man page for > curl_formadd: https://curl.haxx.se/libcurl/c/curl_formadd.html > > > -- > > / daniel.haxx.se > ------------------------------------------------------------------- > Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library > Etiquette: https://curl.haxx.se/mail/etiquette.html >
------------------------------------------------------------------- Unsubscribe: https://cool.haxx.se/list/listinfo/curl-library Etiquette: https://curl.haxx.se/mail/etiquette.html
