Webservice using https

ShaktaShakta Member Posts: 9
Hello All

I'm new to webservices and have a problem, i hope you can help me with.

I need to send a XML message via https.

If i use Navision code to do the same task (found alot of good info around mibuso :)) then i get I get the response : "401 Unauthorized"??? and i have checked the output from the base64 encoding. What can the problem be, since i get a response?
// Using the Base 64 encode with streams 
// to generate the password 
int:= PassOutStr.WRITETEXT('xxxxxx:xxxxxxx');
Base64Encode(PassInStr, PassOutStr1);
int:= PassInStr1.READTEXT(Passtxt);
Passtxt := 'Authorization: Basic '+Passtxt;

//the request XMLport fills the BLOB with the XML message 
CLEAR(XP1); 
XP1.SETDESTINATION(OutStr1);
XP1.EXPORT;

//load the message into the XML automation variable 
IF ISCLEAR(XMLDoc) THEN 
  CREATE(XMLDoc); 
XMLDoc.load(InStr1);

//this is for diagnostics only, so you can see what the XMLport actually produced 
XMLDoc.save('C:\XMLRequest.xml');

//create the HTTP connector 
IF ISCLEAR(XMLHttpConn) THEN 
  CREATE(XMLHttpConn); 

//tell it where the web service is located 
XMLHttpConn.open('POST', 'https://www.xxx.xx', FALSE);

//set some values in the request header depending on what the service requires 
XMLHttpConn.setRequestHeader('Content-Type','text/xml');
XMLHttpConn.setRequestHeader('Authorization', Passtxt);

//actually send the message 
XMLHttpConn.send(XMLDoc); 

//tell us if we got an error (it is 200 because the response definition said "200 OK") 
IF XMLHttpConn.status <> 200 THEN BEGIN
  MESSAGE('Status %1 2%',XMLHttpConn.status,XMLHttpConn.statusText); 
  EXIT;
END;

IF ISCLEAR(XMLDoc) THEN 
  CREATE(XMLDoc); 
XMLDoc.load(XMLHttpConn.responseXML);

//this is for diagnostics only, so you can see what you got back 
XMLDoc.save('C:\XMLResponse1.xml');

Any help is appreciated \:D/

Answers

  • ara3nara3n Member Posts: 9,256
    My guess would be Passtxt is not encoded correctly?


    try to compare passtxt in the following website.

    http://www.motobit.com/util/base64-decoder-encoder.asp

    or here
    http://makcoder.sourceforge.net/demo/base64.php
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    Also when you call the .open function you can pass the login and pass as 3rd and 4th paramater without any encoding


    XMLHttpConn.open('POST', 'https://www.xxx.xx', FALSE,login,password);
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ShaktaShakta Member Posts: 9
    Hi ara3n

    Thanks for your fast reply.

    I knew the passtxt was alright, so i tried the second solution. Now i don't get an authorization error, now i just didn't get anything in the file i save. So i guess i found another problem and put in a parseerror function.

    It returns :
    The system cannot locate the object specified. Error processing resource 'xxxxx.dtd'.
    Errorcode : -2146697210

    Now i just need a dtd document in my system, but where do i put this?
  • ara3nara3n Member Posts: 9,256
    I would remove this line from your htm file

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    Or change it to a location and specify the .dtd file and put the dtd file in there.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ShaktaShakta Member Posts: 9
    Hi ara3n

    Thanks again for your answers.

    It is the response i get back and the XMLDom can not parse this response, because it needs the dtd document in the system, but i don't know where to put this document?

    In the response i get :
    <!DOCTYPE quote SYSTEM "quote.dtd">
    

    So i hoped that someone knew where to put it or what to do with dtd files to make the system know where it is.
  • ara3nara3n Member Posts: 9,256
    I would try and google it.

    Here is a person having the same proble but with excel

    http://forums.techguy.org/business-appl ... ource.html
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ara3nara3n Member Posts: 9,256
    btw where are you getting this error, In navision?
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ShaktaShakta Member Posts: 9
    I used the following code
    IF XMLDoc.parseError.errorCode <> 0 THEN
      ERROR('XML DOM Error: ' +XMLDoc.parseError.reason +' - Errorcode : '+FORMAT(XMLDoc.parseError.errorCode));
    

    That's where i got my error.

    To bad i can't solve the problem the same way as the excel guy :(
  • ara3nara3n Member Posts: 9,256
    you could try and set the DTD parsing off



    xmlDoc.validateOnParse := false;
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • ShaktaShakta Member Posts: 9
    Hi ara3n

    I did try that and that didn't help, but i found another solution.

    First i used this automation :
    'Microsoft XML, v6.0'.DOMDocument

    And by a mistake i picked another :
    'Microsoft XML, v6.0'.DOMDocument60

    Then the following code worked
    //get the response
    IF ISCLEAR(XMLDoc) THEN 
      CREATE(XMLDoc);
    
    XMLDoc.validateOnParse( FALSE );
    XMLDoc.setProperty('ProhibitDTD', FALSE);
    XMLDoc.load(XMLHttpConn.responseXML);
    IF XMLDoc.parseError.errorCode <> 0 THEN
      ERROR('XML DOM Error: '+XMLDoc.parseError.reason +' - Errorcode : '+FORMAT(XMLDoc.parseError.errorCode));
    

    Thanks for you help all the way \:D/
  • ara3nara3n Member Posts: 9,256
    You are welcome. Good luck.
    Ahmed Rashed Amini
    Independent Consultant/Developer


    blog: https://dynamicsuser.net/nav/b/ara3n
  • fredefrede Member Posts: 80
    Hi Shakta!

    Can you help with Base64Encode - as I'm going to communicate via POST-https - and as I see it - we have a problem with sending password...As you had...

    Can you guide me a little?
    Regards,

    Henrik Frederiksen, Denmark
Sign In or Register to comment.