I want to send request with content-type “multipart/form-data”, but i don’t find anything for this subject in documentation. I try with Assign messag policy, with set a payload with this type of content-type, but it’s not working…
For example, the request need looks like this :
sent request like this one : POST /api/rest/email/send HTTP/1.1 Host: edf-smartpush.aw.atos.net Authorization: Bearer ebcAahMk58
I already seen this post. If my understanding is good, this post talking about how we can handling multipart in response. But my issue is when i want sent a request with multipart.
Got it, Thank you for more details. Indeed, it’s an interesting use case & great question. Let me think about it & come up with a solution. Can you share the web service documentation if any so that I can play with same if it is public?
Below code can be used to generate the multipart payload from JSON
var jsonFormData = {
'from': "'API Support'<superteamxxx@google.com>",
'html': "Dear API Support Team,<br/><br/>Below IP address has been detected exceeding allowed request limit <br/><br/> Thanks,<br/> API Team ",
'to': "johncharterxxx@gmail.com",
'subject': "Alert, Exceeding Allowed API Request Limit"
};
function getMultipartPayload(inputJson, boundary){
var formPayload = "";
var keys = Object.keys(inputJson);
keys.forEach(function (key){
formPayload = formPayload + "------"+boundary+"\r\n"+"Content-Disposition: form-data; name=\""+key+"\"\r\n\r\n"+inputJson[key]+"\r\n"
});
formPayload+= "------"+boundary+"--";
return formPayload;
}
//Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW
//Use the same boundary value as in headers
var finalMultipartPayload = getMultipartPayload(jsonFormData, "WebKitFormBoundary7MA4YWxkTrZu0gW");