web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

Send HTTP POST using text file through NAV 2016 and Get Response

(0) ShareShare
ReportReport
Posted on by

Hi Experts,

    I need to send HTTP Request using text file, and need to get Respone.

In the case of XML file It's done.

But in the case of text file I could not get.

Could you please give me suggestion to send HTTP Request using text file through NAV 2016.

 

Thanks in Advance. 

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Rabin Profile Picture
    2,976 on at

    Hello Satya,

    You might would like to see this as well. 
    Let us know if you have any luck with it. 

    Regards
    Rabindra Sah
    Microsoft Dynamics Consultant NAV/CRM

    [View:https://community.dynamics.com/nav/f/34/t/130168:750:50]

  • Verified answer
    keoma Profile Picture
    32,729 on at
  • Community Member Profile Picture
    on at

    Thanks for your response  Rabindra Sah and Jonathan Archer,

    Provided solutions are what I am required.

    I checked both solutions.

    But it's not done.

    I am getting error, like invalid request and invalid credentials.

    So I need to check data.

    Let you know, After completion of this successfully.

    If you have any other suggestions welcome.

  • keoma Profile Picture
    32,729 on at

    did you debug?

    do you set special credentials or do you use defaultcredentials=true?

  • Suggested answer
    Community Member Profile Picture
    on at

    Hi All,

    For above my requirement I'm following this link.

    There I found C# code.

    I replaced with .Net Variables in Nav 2016.

    Then It's working Fine.

    (Note: In that code, I gave XMLHTTPRequestL.ContentType := 'text/xml; 

    at that time I got error 'Missing or Invalid Credentials'

    Now I Changed as follows

    XMLHTTPRequestL.ContentType := 'application/x-www-form-urlencoded';

    Now it's working Fine with out any issue.)

    Code as follows...............................

    Variables:-

    Name DataType Subtype Length

    SourceXMLDoc  DotNet  System.Xml.XmlDocument.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089', 
    XMLDOMText DotNet System.Xml.XmlText.'System.Xml, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' 
    XMLHTTPRequestL DotNet System.Net.HttpWebRequest.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    MemoryStreamL DotNet System.IO.MemoryStream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    MemoryStreamResL DotNet System.IO.MemoryStream.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    XMLHTTPResponse DotNet System.Net.HttpWebResponse.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    EncodingUTF8 DotNet System.Text.UTF8Encoding.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    Bytes DotNet System.Array.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    StreamReaderL DotNet System.IO.StreamReader.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'
    credentials DotNet System.Net.CredentialCache.'System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'

    Code.......................


    IF ISNULL(SourceXMLDoc) THEN
    SourceXMLDoc:=SourceXMLDoc.XmlDocument;

    IF ISNULL(XMLHTTPRequestL) THEN
    XMLHTTPRequestL := XMLHTTPRequestL.HttpWebRequest;
    IF ISNULL(XMLHTTPResponse) THEN
    XMLHTTPResponse := XMLHTTPResponse.HttpWebResponse;

    XMLHTTPRequestL := XMLHTTPRequestL.Create(ReqestURL);

    XMLHTTPRequestL.Timeout := 30000;
    XMLHTTPRequestL.UseDefaultCredentials(FALSE);
    XMLHTTPRequestL.ContentType := 'application/x-www-form-urlencoded';
    XMLHTTPRequestL.Method := 'POST';

    Bytes:=EncodingUTF8.UTF8.GetBytes(XMLDOMText.Value);
    XMLHTTPRequestL.ContentLength:=Bytes.Length;

    MemoryStreamL := XMLHTTPRequestL.GetRequestStream;
    MemoryStreamL.Write(Bytes,0,Bytes.Length);
    MemoryStreamL.Flush;
    MemoryStreamL.Close;

    XMLHTTPResponse := XMLHTTPRequestL.GetResponse;
    MemoryStreamResL := XMLHTTPResponse.GetResponseStream;
    SourceXMLDoc.Load(MemoryStreamResL);
    MemoryStreamResL.Flush;
    MemoryStreamResL.Close;
    XMLHTTPResponse.Close;

    IF XMLHTTPResponse.StatusCode <> 200 THEN BEGIN
    SourceXMLDoc.Save(ResponseFileName+'Failed_HTTP_Response.xml');
    END ELSE BEGIN
    SourceXMLDoc.Save(ResponseFileName+'Valid_HTTP_Response.xml');
    END;

       

  • Suggested answer
    Rabin Profile Picture
    2,976 on at

    Hi Satya,

    The code looks great... The greatness about C# compilers is that you can easily trace this kind of errors.

    FYI if you have not read it...,

    Even NAV 2016 has implemented many features for C/AL Compilers like IntelliSense, Exception Handling and Writing Test case...

  • Community Member Profile Picture
    on at

    Thank you sir,

    NAV 2016 is more implemented

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

#1
HoangNam Profile Picture

HoangNam 7

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans