Unbenanntes Dokument
https://portal.etm.at/index.php?=primary-homework-help-co-uk-adaptations-desert/
gotham creative writing 101 | https://portal.etm.at/index.php?=i-need-to-write-my-essay/
-->
Home ETM FAQ Tips & Tricks How to send form data via http post including file content

Email Print

How to send form data via http post including file content

Date added:
Friday, 28 September 2018
Last revised:
never
Hits:
208
Rating:
 
Vote for this:
Good - Bad

Answer

When accessing Webservices with WinCC OA it can be necessary to send files with form data. For example this can be useful to send pictures to a messaging service.

This small code example shows how this can be achieved and it can be easily adapted to your needs:

    blob binary, bContent;
    file f;
    int read;
    
    //opens a file and read it binary to a blob
    f = fopen("path to your file", "rb");
    read = blobRead(binary, getFileSize("path to your file"), f);
    fclose(f);

    // create form data, adapt field names and values to your needs
    string boundary=createUuid();
    string sContent=
             "--" + boundary + "\r\n"
             "Content-Disposition: form-data; name=\"photo\"; filename=\"trend.png\"\r\n";

    // if necessary add a content type
    // sContent+="Content-Type: image/png\r\n";
    
    sContent+="\r\n"; // add the seperator
    
    // prepare a blob with form data and the binary stream
    blobAppendValue(bContent, sContent, strlen(sContent));
    blobAppendValue(bContent, binary, read);

    // add an additional form field
    sContent="\r\n"
             "--" + boundary + "\r\n"
             "Content-Disposition: form-data; name=\"chat_id\"\r\n\r\n" +
             "value_of_chat_id_field" + "\r\n"
             "--" + boundary + "--\r\n";
    blobAppendValue(bContent, sContent, strlen(sContent));

    // prepare mapping for post
    mapping m;
    m["headers"]=makeMapping("Content-Type", "multipart/form-data, boundary=" + boundary);
    m["content"] = bContent;

    // post the form data
    int res, ret;
    ret=netPost("your_form_post_url", m, res);

Keywords for this item

Keywords

1 items are tagged with 3.12   1 items are tagged with 3.13   1 items are tagged with 3.14   1 items are tagged with 3.15   1 items are tagged with ALL Versions   1 items are tagged with Engineering   1 items are tagged with Installation / Configuration   4 items are tagged with OOP   6 items are tagged with Programming / Scripting   1 items are tagged with PVSS   2 items are tagged with WinCC Open Architecture   1 items are tagged with Windows  

Search FAQ