I have a JSON object which I am sending in a POST request. It was working fine. But, now I need to send a text file as an attachment as well. I tried the following code:
lv-multiPartEntity = new MultipartEntity().
lv-messagePart = new MessagePart("application/json", lv-requestParameters).
:Value("form-data; name=" + quoter("dataRequest"))
/* ------------- I added this section ---------- */
/* ---------------------------------------------- */
lv-multiPartEntity:AddPart(lv-messagePart). lv-multiPartEntity:Boundary = guid.
lv-request = RequestBuilder
:AddHeader("Authorization", "Bearer " + lv-accessToken)
I am having an error saying "Invalid cast from OpenEdge.core.String to Progress.Json.ObjectModel.JsonObject. (12869) ".
I also tried to add this file as a different messagePart, but it didn't work. What am I missing?Thanks in advance.
I believe, you will need to include boundary to your payload.
Yes. I have used boundary. I missed to include it in above code. Apologies.
Does your code insert the proper header at the beginning of each data segment and a footer at the end of everything.
Structurally speaking your payload should look something like this;
"--" + boundary // header
"--" + boundary + "--" // footer
Those "--" are required. You might just have to use Fiddler to see what it is being sent.
I checked. I think Boundary property of multipartEntity takes care of it. But can we add two headers for the same messagePart? Nothing wrong with my code?
Thank you. I will try that way as well.
The below code worked for me, but I really need to send an attachment, which gives the error!
lv-messagePart = new MessagePart("application/octet-stream", new String(lv-fileLongChar)).
You can add as many headers as you want for the message parts.
IF you want to see what’s being sent , set the logging-level to 5 and otherwise set up the log-manager. The client will dump a request-raw.txt into the session temp-dir (-T); you can see then exactly what’s being sent.