Page 1 of 1

Using POST method to send XML file to the WebAPI

Posted: Tue Dec 07, 2021 11:43 am
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