ofxHTTP how to fill multipart form with file upload

I am trying to fill a web form like this:

the code on the server side (django) is something like that:

> <body><form enctype="multipart/form-data" method="post" action="/writexml/">
>     <label for="id_title">Title:</label><input id="id_title" maxlength="50" name="title" type="text" >
> <label for="id_xml">Xml:</label><input id="id_xml" name="xml" type="file">
> <label for="id_user">User:</label><input id="id_user" maxlength="50" name="user" type="text">
> <label for="id_idstr">Idstr:</label><input id="id_idstr" maxlength="50" name="idstr" type="text">
>     <input type="submit">
> </form>
> </body>

When i try to fill the fields like this:

    std::string url = "https://test1.c9.io/writexml/";

    ofx::HTTP::DefaultClient client;
    ofx::HTTP::Context context;
    ofx::HTTP::BaseResponse response;
    ofx::HTTP::PostRequest post(url, Poco::Net::HTTPMessage::HTTP_1_1);
   
    // I used this too trying to change the encoding to multipart...
    post.setFormEncoding(ofx::HTTP::PostRequest::FORM_ENCODING_MULTIPART);
    
    post.addFormField("title", "title");
    post.addFormField("user", "user001");
    post.addFormField("idstr", "idstr001");
    post.addFormFile("xml","10_empty.xml");

// Execute the request and get the response stream.
            std::istream& responseStream = client.execute(post,
                                                          response,
                                                          context);

But the server replies with “field required errors”:

Title:
  • This field is required.
Xml:
  • This field is required.
User:
  • This field is required.
Idstr:
  • This field is required.

Any help around?

ok. i tryed this:

ofx::HTTP::PostRequest postRequest(url, Poco::Net::HTTPMessage::HTTP_1_1);

postRequest.setFormEncoding(ofx::HTTP::PostRequest::FORM_ENCODING_MULTIPART);

postRequest.addFormField("title", "titlegogogogo");
postRequest.addFormField("user", "usergogogogo");
postRequest.addFormField("idstr", "idstrgogogogo");
postRequest.addFormFile("xml", "settings.xml", "text/xml");
...

std::istream& responseStream = client.execute(postRequest,
                                                      response,
                                                      context);

I am getting the same ‘field required’ errors when using my Django server.
But when using this other server for testing purposes:


https://www.posttestserver.com/

it seems it’s ‘doing something’:

http://www.posttestserver.com/data/2017/10/20/example/13.58.411731205816

Time: Fri, 20 Oct 17 13:58:41 +0000
Source ip: 186.139.156.63

Headers (Some may be inserted by server)
HTTP_USER_AGENT = Mozilla/5.0 (compatible; Client/1.0 +https://github.com/bakercp/ofxHTTP)
HTTP_ACCEPT_ENCODING = gzip, deflate
CONTENT_TYPE = multipart/form-data; boundary=“MIME_boundary_1BBE994C0E3F1BB4”
HTTP_TRANSFER_ENCODING = chunked
HTTP_HOST = posttestserver.com
REMOTE_ADDR = 186.139.156.63
DOCUMENT_ROOT = /var/www/html
REQUEST_SCHEME = http
CONTEXT_PREFIX =
CONTEXT_DOCUMENT_ROOT = /var/www/html
REMOTE_PORT = 53200
GATEWAY_INTERFACE = CGI/1.1
REQUEST_METHOD = POST
QUERY_STRING = dir=example
REQUEST_URI = /post.php?dir=example
PHP_SELF = /post.php
REQUEST_TIME_FLOAT = 1508507921.202
REQUEST_TIME = 1508507921

Post Params:
key: ‘title’ value: ‘titlegogogogo’
key: ‘user’ value: ‘usergogogogo’
key: ‘idstr’ value: ‘idstrgogogogo’
Empty post body.

== Multipart File upload. ==
Received 1 file(s)
0: posted name=xml
name: settings.xml
type: text/xml
error: 0
size: 429
SHA1: aa8734ad24069a5ee6d0fd9fafcb72e5f1ed2454
Uploaded File: http://posttestserver.com/files/2017/10/20/f_13.58.4117110968

… so I don’t know if the problem is related to my django c9.io server… BUT my server is working fine when filling the form manually from the browser and also when using the POSTMAN Rest Client extension for Chrome…

pfff solved changing this:

//    ofx::HTTP::PutRequest putRequest(url, Poco::Net::HTTPMessage::HTTP_1_1);
    ofx::HTTP::PostRequest postRequest(url, Poco::Net::HTTPMessage::HTTP_1_0);

working fine now!