Using POST method to send XML file to the WebAPI

This Q&A forum allows users to post and respond to "How Do I Do ....." questions. Please do not use to report (suspected) errors - you must use your regional help desk for this. The information contained in this forum has not been validated by LANSA and, as such, LANSA cannot guarantee the accuracy of the information.
Post Reply
PoojaSingh
Posts: 3
Joined: Sat Aug 14, 2021 8:27 am

Using POST method to send XML file to the WebAPI

Post by PoojaSingh »

Hi,

I am trying to send xml file in the form of multipart/form-data to the web api.
But it seems if i do not specify content-type header explicitly within Lansa, httprequest takes "application/octet-stream" content type on its own and server rejects to accept my request since it is expecting multipart/form-data.
And When I specify the content-type it expects the boundary to be specified as well and having assigned some random boundary value, I end up with response error code 500.

Below is the code snippet :
Define_Com Class(#XPRIM_HttpRequest) Name(#Req)
#Req.Clear
#Req.Options.AddBearerAuthorization Value(#AccessToken)
* #Req.Options.AddHeader Name('Content-Type') Value('multipart/form-data; boundary=--698208317375--')
#Req.Content.AddFile Path(#FullPath)
#Req.DoPost Url(#URL)
If Cond(*Not #Req.Response.IsSuccessHttpStatusCode)
// error handling
else
// Success response parsing
endif

Error received when content type is not specified : Exception while executing function: XXXX Incorrect Content-Type: application/octet-stream

Error received after adding content type and boundary info : Unexpected end of Stream, the content may have already been read by another component

Could someone please help me understand what am I missing? or where it went wrong?

Thank you in advance!

Best regards,
Pooja
Post Reply