Send file using Httppost - ADVPL

Asked

Viewed 1,622 times

0

I am trying to send an xml file using Httppost.

cUrl := "www.test.com"
cPostParms := 'mod=Upload'
cGetParms:=""
cHeadRet := ""
aHeadOut := {User-Agent: Mozilla/4.0 (compatible; Protheus '+GetBuild()+'}

HttpPost(cUrl, cGetParms, cPostParms, nTimeOut, aHeadOut, @cHeadRet)

I cannot use Httppostxml, because in my case I need to send a flag in the header and this other method does not allow.

This link below says that it is possible to send via Httppost, but does not explain

http://tdn.totvs.com/display/tec/HTTPPostXml

Someone would know?

Thank you

  • The documentation is not the best, see if that help you.

  • This TDN documentation has no example for file uploading.

  • Shouldn’t you be passing XML on the Post body? (cPostParams)

  • I’ve tried, but it seems Protheus isn’t riding properly.

1 answer

1

For the use of the function HTTPPost() for sending an XML file, initially the XML file must be loaded into memory in a character variable, which must be specified as parameter in cPostParms -- this makes the content to be posted go into the "body" of Post. You can read the disk file using for example the function Memoread().

cPostPArms := Memoread('\xml\MyXmlFile.xml')

And, in the array aHeadOut, you must add the header stating that you are sending an XML : Before doing the post, run:

aadd(aHeadOut,"Content-Type: text/xml")

References:

http://tdn.totvs.com/display/tec/MemoRead

  • My problem is sending the content in "Body" and how to send other parameters should be yydd(aHeadOut,"Content-Type: form-data")

  • 1

    Depending on how your HTTP server is waiting I will delay this POST, it may be necessary to send more than one Header -- such as "Content-Type: Multipart/form-data"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.