Webservice using https
Shakta
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?
Any help is appreciated \:D/
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
// 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/
0
Answers
-
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.php0 -
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);0 -
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?0 -
I would remove this line from your htm file
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">0 -
Or change it to a location and specify the .dtd file and put the dtd file in there.0
-
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.0 -
I would try and google it.
Here is a person having the same proble but with excel
http://forums.techguy.org/business-appl ... ource.html0 -
btw where are you getting this error, In navision?0
-
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
0 -
you could try and set the DTD parsing off
xmlDoc.validateOnParse := false;0 -
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/0 -
You are welcome. Good luck.0
-
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, Denmark0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 327 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions
