Hi All,
I'm calling a web service through X++, but it's giving me 401 Unauthorized because of OAuth 2.0, can anyone please help me on adding the header authorization to my request. here is my code, note that i can make c# project and add it as a reference but im looking to have it here through X++ instead.
System.Net.HttpWebRequest webRequest;
System.IO.Stream stream;
System.Net.ServicePoint servicePt;
System.Text.Encoding utf8;
System.Byte[] bytes;
System.String sysString;
System.IO.StreamReader streamReader = null;
//For OAuth
str aadTenant;
str aadClientAppId;
str aadClientAppSecret;
str aadResource;
utf8 = System.Text.Encoding::get_UTF8();
bytes = utf8.GetBytes(jsonRequest);
clrObj = System.Net.WebRequest::Create(url);
webRequest = clrObj;
webRequest.set_Method('POST');
webRequest.set_KeepAlive(true);
webRequest.set_ContentType('application/json');
webRequest.set_ContentLength(bytes.get_Length());
servicePt = webRequest.get_ServicePoint();
servicePt.set_Expect100Continue(false);
stream = webRequest.GetRequestStream();
stream.Write(bytes,0,bytes.get_Length());
stream.Close();