Personalized Community is here!
Quickly customize your community to find the content you seek.
Choose your path Increase your proficiency with the Dynamics 365 applications that you already use and learn more about the apps that interest you. Up your game with a learning path tailored to today's Dynamics 365 masterminds and designed to prepare you for industry-recognized Microsoft certifications.
Visit Microsoft Learn
2021 Release Wave 2Discover the latest updates and new features releasing from October 2021 through March 2022.
2021 release wave 2 plan
The FastTrack program is designed to help you accelerate your Dynamics 365 deployment with confidence.
FastTrack Community | FastTrack Program | Finance and Operations TechTalks | Customer Engagement TechTalks | Upcoming TechTalks | All TechTalks
I need some help to send Http Post. How this can be done in NAV 2013.
you can't do this directly in C/AL. What you can do is use or write a .net component which does the network handling. Also, COMMANDLINE or SHELL is no longer supported in NAV2013 (R2), so using curl or wget is out.
with best regards
Thanks for the reply. I am newbie in NAV. Can use XMLHttpRequest in NAV instead? I was tasked to look into the possibility to provide Push Notification From NAV to Mobile phone VIA Microsoft Push Notification Services. All I need is to send a Http post from NAV. Since Http is out of the question, is XMLHttprequest available to NAV?
NAV has no direct interface to send network requests via C/AL. You can use all .net classes, though. A little search has turned up a possible example on how to do this.
I created a code unit using .Net that uses http post to call web services. I am sure you can adapt it to fit your needs.
OBJECT Codeunit 50098 Call To Webservice
Time=[ 7:38:56 AM];
PROCEDURE fncSendToWebservice@1000000011(xml@1000000000 : Text;url@1000000001 : Text;soapActionUrl@1000000002 : Text) : Text;
sb@1000000003 : DotNet "'mscorlib, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.StringBuilder";
uriObj@1000000004 : DotNet "'System, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Uri";
lgRequest@1000000005 : DotNet "'System, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebRequest";
stream@1000000006 : DotNet "'mscorlib, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.StreamWriter";
lgResponse@1000000007 : DotNet "'System, Version=126.96.36.199, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.HttpWebResponse";
str@1000000008 : DotNet "'mscorlib, Version=188.8.131.52, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.IO.Stream";
reader@1000000009 : DotNet "'System.Xml, Version=184.108.40.206, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlTextReader";
document@1000000010 : DotNet "'System.Xml, Version=220.127.116.11, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Xml.XmlDocument";
ascii@1000000011 : DotNet "'mscorlib, Version=18.104.22.168, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Text.Encoding";
credentials@1000000012 : DotNet "'System, Version=22.214.171.124, Culture=neutral, PublicKeyToken=b77a5c561934e089'.System.Net.CredentialCache";
sb := sb.StringBuilder();
sb.Append('<soap:Envelope xmlns:xsi="www.w3.org/.../XMLSchema-instance" xmlns:xsd="www.w3.org/.../XMLSchema" xmlns:soap="schemas.xmlsoap.org/.../"><soap:Body>&);
uriObj := uriObj.Uri(url);
lgRequest := lgRequest.CreateDefault(uriObj);
lgRequest.Method := 'POST';
lgRequest.ContentType := 'text/xml';
lgRequest.Credentials := credentials.DefaultCredentials;
lgRequest.Timeout := 120000;
stream := stream.StreamWriter(lgRequest.GetRequestStream(), ascii.ASCII);
lgResponse := lgRequest.GetResponse();
str := lgResponse.GetResponseStream();
reader := reader.XmlTextReader(str);
document := document.XmlDocument();
Hi Kevin, thank you for code, however I have ambiguous error on line "reader := reader.XmlTextReader(str);" during compilation:
The call is ambiguous between the following methods:
because there are two constructors XmlTextReader with one parameter. How did you solve this issue?
The same ambiguous error on line "document.Load(reader);"
I copied the code from above this morning and pasted it into a text file. For some reason when I pasted it originally, it changed a single quote (') to a (&) in the line that ends with soap:Body>&);. Otherwise I imported the code into NAV 2013 and compiled it without issue.
Do you have the .Net Framework 4.0 installed on your machine? Sometimes a newer version doesn't actually install all of the pieces of the older versions. It is also possible that NAV is fussy in the order in which you declare the variables. The above order was how I called them.
The 'Str' variable is defined as System.IO.Stream so it should be obvious to the compiler that is the constructor to use. I am using a minor variation of this code in Production so I know it is working.
Business Applications communities