HttpWebRequest credentials

danskretaildanskretail Member Posts: 4
edited 2015-06-17 in NAV Three Tier
We are moving from Nav 2009 to 2015. In 2009 I have a call to a web service where I use the 'Microsoft XML, v3.0'.XMLHTTP' automation, and send username and password like this 'XmlHttp.open('POST',txtURL, FALSE, UserID,Password);'

in 2015 I want to use 'System.Net.HttpWebRequest' Dotnet.

I cant figure out how to pass credentials to the webrequest, it seems like I should be creating an instance of the 'System.Net.CredentialCache' but i cant access this class from Dynamics Nav.

Any ideas ?

BR

Peter

Comments

  • BardurKnudsenBardurKnudsen Member, Microsoft Employee Posts: 137
    Take a look in NAV2015, codeunit 1290 where there are similar usages.
    Bardur Knudsen
    Microsoft - Dynamics NAV
  • danskretaildanskretail Member Posts: 4
    Hi Baldur

    Thank you for the answer.

    I've allready been looking ind CU 1290, but I cant find an example on how to specify username and password.

    Instead i've tried to use a header value like this, but this gives me an error 401

    HttpRequestHeader := HttpWebRequest.Headers();
    HttpRequestHeader.Add('Authorization','Basic Username:Password');
  • danskretaildanskretail Member Posts: 4
    Problem solved

    I found the class System.Net.NetworkCredential

    And then I could handle it like this

    Credentials := Credentials.NetworkCredential(UserName,Password);
    HttpWebRequest.Credentials := Credentials;

    It works fine

    BR

    Peter
Sign In or Register to comment.