Question
· 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

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