HTTPClient POST multipart/form-data request


HI there, i need to replicate this kind of request:

curl -X POST \ \
  -H 'Authorization: Bearer eyJhbGciOiJSUzI1NiJ9 \
  -H 'Cache-Control: no-cache' \
  -H 'Content-Type: multipart/form-data' \
  -H 'Postman-Token: cf70442b-d512-4899-9e69-9691702bcd3e' \
  -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW' \
  -F 'invoice=@C:\Users\Utente\Desktop\Fatturazione_Elettronica\IT01234567890_FPR01.xml'

How should i pass the "invoice" parameter with the attached filename in the body of the request?

any help would be appreciated,


Question Tags: 


René Ullrich answered HTTPClient POST multipart/form-data request


It depends on how many form parts you have.

Here is an example sends XML data in one part and another xml file in a second part:

// xml meta  data

lblob_data = blob ("--"  + ls_BOUNDARY + "~r~n" + &
                 'Content-Disposition: form-data; name="meta"' + &
                 "~r~n~r~n" + ls_xml + "~r~n", EncodingUTF8!)

// a file
lblob_data += blob ("--"  + ls_BOUNDARY + "~r~n" + &
                 'Content-Disposition: form-data; name="file"; filename="stammdaten.xml"' + &
                 "~r~nContent-Type: application/xml~r~n~r~n", EncodingUTF8!) + &
                 ablob_xml + blob ("~r~n--"  + ls_BOUNDARY + "--~r~n", EncodingUTF8!)


The boundary string (ls_boundary) you have to specify in the request header. It is to separate the parts of the message. So it must not be a string that is in one of the message parts.'s picture

thank you Renè, working like a charm!