1

Hi want to upload one single input.zip file as well as this xml descrition of file to the server.This is xml description part that I want to send in CURLOPT_POSTFIELDS,

<data_file>
<archive>"true"</archive>
<data_type_id> "42f7710d-9399-45d8-a61f-a018bb6c33f6""</data_type_id>
<data_file_name> "INPUT.zip"</data_file_name>
<description>..</description>
<uploaded>true</uploaded>
<job_id> job_id</job_id>
</data_file>

and this is libcurl part. I'm not sure if we can send both POST parameters and Postform in same request.

    struct curl_httppost *formpost=NULL;
    struct curl_httppost *lastptr=NULL;
    struct curl_slist *headers=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, filepathinput.c_str(),
             CURLFORM_END);

     /* Fill in the filename field */
     curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "INPUT.zip",
             CURLFORM_COPYCONTENTS, filepathinput.c_str(),
             CURLFORM_END);


     /* Fill in the submit field too, even if this is rarely needed */
     curl_formadd(&formpost,
             &lastptr,
             CURLFORM_COPYNAME, "submit",
             CURLFORM_COPYCONTENTS, "send",
             CURLFORM_END);


      curl = curl_easy_init();
       headers = curl_slist_append(headers, buf);
       headers = curl_slist_append(headers, "Content-Type: multipart/form-data");


 if(curl) {

    curl_easy_setopt(curl, CURLOPT_VERBOSE, true);

    curl_easy_setopt(curl, CURLOPT_URL, url);
    curl_easy_setopt(curl, CURLOPT_USERPWD,_loginCBstring.c_str());
    curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, formpost);


 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, xmldescription.c_str());
     curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(xmldescription.c_str()));

    _res = curl_easy_perform(curl);

    if(_res != CURLE_OK)
        fprintf(stderr, "curl_easy_perform() failed: %s\n",
                curl_easy_strerror(_res));

    curl_easy_cleanup(curl);

    curl_formfree(formpost);
    curl_slist_free_all (headers);
}

Thx a lot in advance!

0 Answers0