Sending an XML file with HTTP

AitorEGAitorEG Posts: 243Member
Hi everyone,

As I wrote in the tittle, I hae to send an XML file via HTTP. But the issue is that, the XML must be converted intro a string, because I have to ad at the start of the file the "xml_in=" text. I am trying to do it in this way:
XMLHTTP.send('"xml_in=' + XMLDocDotNet.OuterXml + '"');

But it looks that is isn't wortking, because I receive in the response an error message. How can I convert the XML file into a string, to concate with "xml_in=", and send it to a server?

Thank you for your help

Best Answers

  • Slawek_GuzekSlawek_Guzek Posts: 1,596
    edited 2017-11-21 Accepted Answer
    Have you tried to put combined string into separate text var
    sometextvar := '"xml_in=' + XMLDocDotNet.OuterXml + '"'
    XMLHTTP.send(sometextvar);
    

    I personally prefer to build complete parameter string before passing somewhere, especially to a .NET variable/component, so I can examine the result in the debugger and make sure it is correct. Maybe you messed up with delimiters, single / double apostrophes, etc - it's not an easy thing to spot when you building a string on the fly.

    Also - an XML prepended with xml_in= is no longer a valid XMLs.. Could it be an issue?

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Slawek_GuzekSlawek_Guzek Posts: 1,596
    Accepted Answer
    I think that the truncation is caused by the debbuger - it simply does not send the whole string to the clipboard.

    To be sure add a bit of code writting content of the big text var to a temporary file, and examine the file.

    By the way - you don't have to use the BigText anymore, in RTC a regular text can be as long as BigText.

    You could try to send the xml without the "xml_in=" prefix and see what happens without waiting for an anwer :)

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Slawek_GuzekSlawek_Guzek Posts: 1,596
    Accepted Answer
    Wireshark is a generic network traffic analyser.. It might be a bit overwhelming indded, sorry.

    There is another similar tool - Fiddler, which is web traffic orientated, might be easier to use.

    Have they told you exaclty what the problem is ?

    BTW - there is another thread on Mibuso, mentioning a custom DLL used to send XML over HTTP. Not much info ion there, but you coulds try to PM the user, maybe he will be able and willing to help

    Slawek

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03

Answers

  • Slawek_GuzekSlawek_Guzek Posts: 1,596Member
    edited 2017-11-21 Accepted Answer
    Have you tried to put combined string into separate text var
    sometextvar := '"xml_in=' + XMLDocDotNet.OuterXml + '"'
    XMLHTTP.send(sometextvar);
    

    I personally prefer to build complete parameter string before passing somewhere, especially to a .NET variable/component, so I can examine the result in the debugger and make sure it is correct. Maybe you messed up with delimiters, single / double apostrophes, etc - it's not an easy thing to spot when you building a string on the fly.

    Also - an XML prepended with xml_in= is no longer a valid XMLs.. Could it be an issue?

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Posts: 243Member
    edited 2017-11-22
    First of all, thank you for your answer @Slawek_Guzek .

    About your question of the valid XML, have to say that it looks it doesn't mind. From support of the service, they've told me that wat i have to send is a variable like "xml_in="+XML(content), but I'e asked directly about this issue, we'll see what's the answer.

    About your advice, I have created the variable in this way:
    XMLText.ADDTEXT('xml_in=');
    XMLText.ADDTEXT(XMLDocDotNet.OuterXml,8);
    SLEEP(6000);
    XMLHTTP.send(XMLText);
    

    As you can imagine, XMLText is a bigText variable, because the XML file is quite big. And here comes the issue I've just realized. I have debugged tha development, and see this:
    6by9vu53dawu.png

    At first lok, it seems that the variable adding the fields correctly. But I copy the content of the "value" ceel in a notepad app, and I can see that it hasnt taken allthe content of the XML file, it is just cutting it, so I'm not sending all the content.

    How can I solve this?

    Really appreciate your help, thank you!!


    edit: the service provider has confirmed that the service receives a text
  • Slawek_GuzekSlawek_Guzek Posts: 1,596Member
    Accepted Answer
    I think that the truncation is caused by the debbuger - it simply does not send the whole string to the clipboard.

    To be sure add a bit of code writting content of the big text var to a temporary file, and examine the file.

    By the way - you don't have to use the BigText anymore, in RTC a regular text can be as long as BigText.

    You could try to send the xml without the "xml_in=" prefix and see what happens without waiting for an anwer :)

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Posts: 243Member
    edited 2017-11-22
    I think that the truncation is caused by the debbuger - it simply does not send the whole string to the clipboard.

    Yes, I've just read it in the bigText documentation.
    To be sure add a bit of code writting content of the big text var to a temporary file, and examine the file.

    That it's my next step, and what I'm, trying to find out how to do, at least to be sure that I create the whole text correctly. How can be an esay way tho do this?
    You could try to send the xml without the "xml_in=" prefix and see what happens without waiting for an anwer :)

    I've already done it, but I take an error back. It is mandatory to send it with "xml_in"


  • AitorEGAitorEG Posts: 243Member
    Thank you @Slawek_Guzek for your tips. I have created a txt file, and i saved there my variable, and it looks that everything is correct, I have there all the content of the XML. Thsi is how i am trying to send the variable
    IF ISCLEAR(XMLHTTP) THEN
      CREATE(XMLHTTP,FALSE,TRUE);
    XMLHTTP.open('POST', 'https://XXXXXX.com/expressconnect/shipping/ship', FALSE);
    XMLHTTP.setRequestHeader('Content-Type: ', 'text/xml; charset = utf-8');
    SLEEP(6000);
    XMLText := 'xml_in=' +  XMLDocDotNet.OuterXml;
    SLEEP(6000);
    XMLHTTP.send(XMLText);
    
    MyFile.CREATE('C:\XML\text\MyWriteText.txt');
    MyFile.CREATEOUTSTREAM(MyOutStream);
    MyOutStream.WRITETEXT(XMLText);
    
    IF ISCLEAR(locautXmlDoc) THEN
      CREATE(locautXmlDoc,FALSE,TRUE);
    
    
    locautXmlDoc.load(XMLHTTP.responseXML);
    locautXmlDoc.save('C:\XML\response\TNT.xml');
    


    Can you se here something that is needed or the absence of something? Thnak you very much again, really really appreciated!!
  • Slawek_GuzekSlawek_Guzek Posts: 1,596Member
    I'm sorry, I have not used XMLHTTP automation so far so cannot really help much.

    Are you sure that the genuine error is returned, and the problem is not caused by this line:
    locautXmlDoc.load(XMLHTTP.responseXML);
    
    The reason is that, despite you have posted in NAV Three Tier using CREATE(XMLHTTP,FALSE,TRUE); in your code suggests Classic Client. If it is the case then if XMLHTTP.responseXML returns serialized XML it migh get truncated

    I'd suggest to put the response into a file in the same way as you did with the request XML, and examine what is exaclty returned.

    If you want to receive in Classinc Client anyting longer than 1024 character you must find a component from which you can stream out the response.
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Posts: 243Member
    edited 2017-11-22
    Thanks @Slawek_Guzek

    This is the error I'm getting, saved with the locautXmlDoc variable:
    <?xml version="1.0" encoding="UTF-8" standalone="true"?>
    
    <runtime_error>
    
    <error_reason>No data received at gateway from client error</error_reason>
    
    <error_srcText/>
    
    </runtime_error>
    

    What are you suggesting to do?

    It's a known error, and it is about a incorrect format in the received file. But it looks that everything is OK, becasue I've saved the generated file before sending into a file, and looks correct.... I am waiting fior the provider's answer, and maybe They can help looking what are they receiving when I make the request.

    Thank you again!
  • Slawek_GuzekSlawek_Guzek Posts: 1,596Member
    edited 2017-11-22
    That's a legit response from the remote service. Which means there is some communication and remote peer cannot understand the input. I don't think if you can do anything more except waiting for the support answers

    Personally, I would be still very, very suspicious about prepending the valid xml with 'xml_in=' and making it non-understandable to any other xml handling software.

    In the meantime, while waiting for remote support answers, you can install a Wireshark (or something similar) and intercept transmission between your PC and remote peer, and double check what is physically transmitted over the network. I don't think it will help in anything in this particular case, but you may have some fun, and do some paranoidal level checks that what you prepared is actually what is transmitted.

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • Slawek_GuzekSlawek_Guzek Posts: 1,596Member
    By the way - in your first post your line of code included a double quote character in front of 'xml_in=', and at the end of XML message. Later version with BigText does not have it.

    Slawek
    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Posts: 243Member
    Really thanks for your answers @Slawek_Guzek , really appreciated.
    The support has emphasized that the server receives a text, and as I've said, it looks that the received one is correct. During today I will get in touch with them, hopefully I will get an anser, and I will post it here.
    Thank you again for all your tips.
  • AitorEGAitorEG Posts: 243Member
    edited 2017-11-23
    As the support tell me just now, it looks that I have some proble generating the header of the request.

    pd: I'm, trying to use the wireshark, but i cannot understand anything... :/
  • Slawek_GuzekSlawek_Guzek Posts: 1,596Member
    Accepted Answer
    Wireshark is a generic network traffic analyser.. It might be a bit overwhelming indded, sorry.

    There is another similar tool - Fiddler, which is web traffic orientated, might be easier to use.

    Have they told you exaclty what the problem is ?

    BTW - there is another thread on Mibuso, mentioning a custom DLL used to send XML over HTTP. Not much info ion there, but you coulds try to PM the user, maybe he will be able and willing to help

    Slawek

    Slawek Guzek
    Dynamics NAV, MS SQL Server, Wherescape RED;
    PRINCE2 Practitioner - License GR657010572SG
    GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
  • AitorEGAitorEG Posts: 243Member
    The problem is that they cannot see in the server the calls that have failed, so they can't see what is wrong with my request. The format of the sent message is correct, so the problem should be in the generation of the request, the hedaers, or something like that...
  • AitorEGAitorEG Posts: 243Member
    Thanks @Slawek_Guzek about the Fiddler. I've ran an execution of the request, and I saw this error:
    No Proxy-Authenticate Header is present.

    No WWW-Authenticate Header is present.

    What can this be? Looks that I nedd to add something else in the header....
  • AitorEGAitorEG Posts: 243Member
    YES! I get the response, I realized with the fiddler, really thanks!
    I cannot say how appreciated i am for your help, THANK YOU!
  • matthew.hill@claritasolutions.co.uk[email protected] Posts: 2Member
    edited 2018-07-09
    Sorry to dig up an old thread, but AitorEG, can you expand on what you did to solve the problem? I'm trying to access the same Webservice (I can tell by the URL and the 'xml_in' notation) and I'm getting the exact-same error back form the Webservice.

    Thanks.
  • AitorEGAitorEG Posts: 243Member
    Sorry to dig up an old thread, but AitorEG, can you expand on what you did to solve the problem? I'm trying to access the same Webservice (I can tell by the URL and the 'xml_in' notation) and I'm getting the exact-same error back form the Webservice.

    Thanks.

    Which error are you talking about? During this post, I've found different issues, so it would be easier to help If you give me some info, also to refresh my mind....
  • Thanks for your response.

    The main problem I have is that when I do the HTTP-Post, I get back the error "No data received at gateway from client".

    I see that you discovered, through "Fiddler", that you found it was as a result of an authentication error. I could not get Fiddler to work, so I do not know if I have the same problem.

    What did you do to fix the authentication error, did you have to set the "Authentication Type" (I have seen this in the supplier's documentation)? Or did you do something else?

    I'm really struggling to get this integration project to work, I'm greatful of any insights you could offer, thanks.
  • AitorEGAitorEG Posts: 243Member
    Thanks for your response.

    The main problem I have is that when I do the HTTP-Post, I get back the error "No data received at gateway from client".

    I see that you discovered, through "Fiddler", that you found it was as a result of an authentication error. I could not get Fiddler to work, so I do not know if I have the same problem.

    What did you do to fix the authentication error, did you have to set the "Authentication Type" (I have seen this in the supplier's documentation)? Or did you do something else?

    I'm really struggling to get this integration project to work, I'm greatful of any insights you could offer, thanks.

    Hi,

    I don't know if this will help you. I also find lots of problems with this integration and now I'm not quite sure about which were the issues and the solutions.
    I don't know why ou can't install fiddler, but I really recommend you, for watching the problems, and aksio, to see which is the ansewr from the service, to use it correctly.

    This is how I create the HTTP request:
    IF ISCLEAR(XMLHTTP) THEN
      CREATE(XMLHTTP,FALSE,TRUE);
    XMLHTTP.open('POST', 'https://express.tnt.com/expressconnect/shipping/ship', 0,'user','password');
    XMLHTTP.setRequestHeader('Content-Type: ', 'application/x-www-form-urlencoded');
    XMLHTTP.setRequestHeader('Host','express.tnt.com');
    XMLHTTP.setRequestHeader('SOAPAction', 'https://XXXXX.com/XXXXXX/shipping/ship');
    
    SLEEP(1000);
    XMLText := 'xml_in=' +  XMLDocDotNet.OuterXml;
    SLEEP(1000);
    XMLHTTP.send(XMLText);
    
    MyFile.CREATE('C:\XML\text\ShippingRequest_xml_in.txt');
    MyFile.CREATEOUTSTREAM(MyOutStream);
    MyOutStream.WRITETEXT(XMLText);
    
    
    IF ISCLEAR(locautXmlDoc) THEN
      CREATE(locautXmlDoc,FALSE,TRUE);
    
    response := XMLHTTP.responseText;
    completeNo := COPYSTR(response, 10, 10);
    EXIT(completeNo);
    

    Compare it with your code and see if it works, or the issue is in another part of the code...
    Tell me when you know something
  • MattHMattH Posts: 11Member
    Result! Your code appears to have worked, in so much that I get back a message with the ticket ID. It's basically the same as mine with the exception that it's using Automation whereas I had tried to do it with .net variables.

    Many thanks.
  • AitorEGAitorEG Posts: 243Member
    MattH wrote: »
    Result! Your code appears to have worked, in so much that I get back a message with the ticket ID. It's basically the same as mine with the exception that it's using Automation whereas I had tried to do it with .net variables.

    Many thanks.

    Perfect! I've also have lots of problem with .NET, automations... I spent lot of time with this issue, until I finally found the solution. Happy that this helped you!
  • MattHMattH Posts: 11Member
    Just wondering if you received any "Error: 500" Javascript messages when you replied back (e.g. to request the label), using the Token ID that you recieved in the "COMPLETE" message?
  • AitorEGAitorEG Posts: 243Member
    MattH wrote: »
    Just wondering if you received any "Error: 500" Javascript messages when you replied back (e.g. to request the label), using the Token ID that you recieved in the "COMPLETE" message?

    A 500 in the response for example when yo are calling to the label service? I don't know, but probably yes.. In which situation¿?
  • MattHMattH Posts: 11Member
    edited 2018-07-26
    I'm sending (using the exact-same interface) xml_in=GET_LABEL:nnnnnn and expecting something back, but get this "Error 500" instead (something to do with Javascript). I'm of course replacing 'nnnnnn' with the 'Token ID'

    I have even sent the XML file that they have given me (with all of the Usernames, passwords and Account Nos. embeded in it) and receive the same error.

    I'm finding the support being offered from *** to be of zero use!
  • AitorEGAitorEG Posts: 243Member
    MattH wrote: »
    I'm sending (using the exact-same interface) xml_in=GET_LABEL:nnnnnn and expecting something back, but get this "Error 500" instead (something to do with Javascript). I'm of course replacing 'nnnnnn' with the 'Token ID'

    I have even sent the XML file that they have given me (with all of the Usernames, passwords and Account Nos. embeded in it) and receive the same error.

    I'm finding the support being offered from *** to be of zero use!

    This is how I use the label service, I don't know if it will help you....
    XMLHTTP.open('POST', 'https://xxxx.xxxx.com/xxxxxx/documentation/getlabel', 0,'xxxxxxxx','xxxxxxx');
    XMLHTTP.setRequestHeader('Content-Type: ', 'application/x-www-form-urlencoded');
    XMLHTTP.setRequestHeader('Host','express.xxx.com');
    XMLHTTP.setRequestHeader('SOAPAction', 'https://express.xxx.com/expresslabel/documentation/getlabel');
    SLEEP(1000);
    
    XMLText := 'xml_in=' +  XMLDocDotNet.OuterXml;
    SLEEP(1000);
    XMLHTTP.send(XMLDocDotNet.OuterXml);
    
    ResponseText := XMLHTTP.responseText;
    LoadXMLDocumentFromText(ResponseText, locautXmlDoc);
    
  • MattHMattH Posts: 11Member
    Thanks for the tips, I now seem getting an XML document in response. Just one thing, how does this XML get rendered into a printable HTML or PDF document?
  • AitorEGAitorEG Posts: 243Member
    MattH wrote: »
    Thanks for the tips, I now seem getting an XML document in response. Just one thing, how does this XML get rendered into a printable HTML or PDF document?

    Sorry forthe delay, I've been on holidays... What I've done, is to get the different fields needed from the XML, save them into the database, and use those flieds when desingning the report
  • MattHMattH Posts: 11Member
    edited 2018-09-04
    OK, thanks. I did contemplate putting the data into a table and printing from there, but in the end I used the "XSL" they provided to give an HTML page.
Sign In or Register to comment.