NetTalk Central

Author Topic: problem to Post XML to an URL  (Read 2153 times)

tglomb

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
    • AObit Software
    • Email
problem to Post XML to an URL
« on: September 24, 2018, 01:08:24 PM »
Hello,
I must Post (NetWebClient) XML data to an URL:Port. Somehow it doesnt works. Here my Code:

mycstring= '@XMLDATA=<?xml version="1.0" encoding="UTF-8"?>' & crlf & |
       '<methodCall>' & crlf & |
         '<methodName>DisplayStudy</methodName>' & crlf & |
         '<params>' & crlf  & |
          ....
         '</params>' & crlf & |
         '</methodCall>'


   sender.SetAllHeadersDefault()
   sender.HeaderOnly = 0
   sender.Cookie = 'Cookie'
   sender.Referer = 'Referer'
   sender.ContentType = 'application/xml'  ! -www-form-urlencoded'
   sender.AcceptEncoding = ''
   sender.Pragma_ = 'no-cache'
   sender.Post( 'http://'& clip( theURLandPort) &'/', mycstring)

What's wrong ?
Any ideas and hints are welcome.

TIA, Thomas

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11158
    • View Profile
Re: problem to Post XML to an URL
« Reply #1 on: September 25, 2018, 03:27:41 AM »
>> What's wrong ?

many possible things, but it all depends on what the other end is expecting.

>> mycstring= '@XMLDATA=<?xml version=

this approach suggests the data is being past as a form-encoded value rather than as XML. If so it's like the actual XML string should be URLEncoded. (See StringTheory for a method on that.) Just the part after the = sign should be URL encoded.
sender.ContentType = 'www-form-urlencoded'

alternatively they may want actual XML - in which case it's likely @XMLDATA= should be drpped, the xml should be "as is" and the
sender.ContentType = 'application/xml'

lastly;
sender.Post( 'http://'& clip( theURLandPort) &'/', mycstring)
should be
sender.Post( 'http://'& clip( theURLandPort) , mycstring)

the trailing / is not desirable.

Cheers
Bruce


tglomb

  • Jr. Member
  • **
  • Posts: 78
    • View Profile
    • AObit Software
    • Email
Re: problem to Post XML to an URL
« Reply #2 on: September 30, 2018, 01:18:26 AM »
Thank you Bruce, it work's like a charm.
In my case I use now:
 mycstring= '<?xml version="1.0" encoding="UTF-8"?>' & crlf & |
       '<methodCall>' & crlf & |
         '<methodName>DisplayStudy</methodName>' & crlf & |
         '<params>' & crlf  & |
          ....
         '</params>' & crlf & |
         '</methodCall>'
 sender.SetAllHeadersDefault()
 sender.HeaderOnly = 0
 sender.Cookie = 'Cookie'
 sender.Referer = 'Referer'
 sender.ContentType = 'application/xml'
 sender.AcceptEncoding = ''
 sender.Pragma_ = 'no-cache'
 sender.Post( 'http://'& clip( theURLandPort), mycstring)
 
Sender is a NetWebClient object, crlf='<13,10>'. Maybe I can drop the crlf.. but it works and not for 20 Bytes or so ;-) there's no chance to play..
Ciao, Thomas