Question
Leonardo Carvalho · Oct 28, 2021

XML file in form-data

Hello everybody

I'm trying to send a XML file in a form-data like this, but is not working. Can anyone help me with the code?

This is my code:

Set HttpRequest = ##class(%Net.HttpRequest).%New()
Set RootMIMEPart = ##class(%Net.MIMEPart).%New()
Set BinaryMIMEPart = ##class(%Net.MIMEPart).%New()

Set stream = ##class(%FileBinaryStream).%New()

Set stream.Filename = pRequest.file
Do stream.LinkToFile(pRequest.file)

Set BinaryMIMEPart.Body = stream

// I already used "application/x-www-form-urlencoded", "application/xml", "application/x-object" in Content-Type

Do BinaryMIMEPart.SetHeader("Content-Type", "application/x-www-form-urlencoded")
Do BinaryMIMEPart.SetHeader("Content-Disposition","form-data; name=""file""; filename="""_pRequest.file_"""")

status = RootMIMEPart.Parts.Insert(BinaryMIMEPart)

Set writer = ##class(%Net.MIMEWriter).%New()
writer.OutputToStream(HttpRequest.EntityBody)
writer.WriteMIMEBody(RootMIMEPart)

Set HttpRequest.ContentType = "multipart/form-data; boundary="_RootMIMEPart.Boundary
Do HttpRequest.SetHeader("Content-Type", "multipart/form-data")

Set status = HttpRequest.Post(..Adapter.URL)

Set tResponse = HttpRequest.HttpResponse

0
0 287
Discussion (4)1
Log in or sign up to continue

you set content-type application/x-www-form-urlencoded
BUT
is your content really urlencoded ?  
If NOT, decoding it may create some chaotic nonsense and definitely no XML

I´ve already used this types:

application/x-www-form-urlencoded - application/xml - application/x-object - application/octet-stream

All of them with tha same result, like the xml file was not attached

That is the correct result:

I´ve already used this types:

application/x-www-form-urlencoded - application/xml - application/x-object - application/octet-stream

All of them with tha same result, like the xml file was not attached

That is the correct result: