Hi,
I'm actually trying to call a WebAPI from code.
The API is running on a IIS which has Windows Authentication activated
I've tried to call it in a job with the code below :
static void TestApi(Args _args) { str url; str byteStr; System.Net.HttpWebRequest request; System.Net.HttpWebResponse response; System.Byte[] byteArray; System.IO.Stream stream; System.IO.Stream dataStream; System.IO.StreamReader streamReader; System.Net.ServicePoint servicePoint; System.Net.WebHeaderCollection httpHeader; CLRObject clrObj, ex; System.Text.Encoding utf8; xml responseXml; ; byteStr = strfmt('%1:%2', "toto", "tata"); new InteropPermission(InteropKind::ClrInterop).assert(); httpHeader = new System.Net.WebHeaderCollection(); url = "http://atl-svax016.atelier.lan:8080/api/DMDLOG/Information/CHG-0000004536"; clrObj = System.Net.WebRequest::Create(url); request = clrObj; request.set_Method("GET"); request.set_KeepAlive(true); request.set_ContentType("application/json"); utf8 = System.Text.Encoding::get_UTF8(); byteArray = utf8.GetBytes(byteStr); byteStr = System.Convert::ToBase64String(byteArray); httpHeader.Add("Authorization", 'NTLM ' byteStr); try { request.set_Headers(httpHeader); response = request.GetResponse(); dataStream = response.GetResponseStream(); streamReader = new System.IO.StreamReader(dataStream); responseXml = streamReader.ReadToEnd(); info(responseXml); } catch (Exception::CLRError) { ex = ClrInterop::getLastException(); if (ex != null) { ex = ex.get_InnerException(); if (ex != null) { error(ex.ToString()); } } else throw error ("Error while connecting API"); } streamReader.Close(); dataStream.Close(); response.Close(); }
But when I execute it i get the error below :
As you can see i'm not authorized to call it even though i'm passing my credentials.
I have tried to call the API from PostMan with NTLM authentication and the same credentials and it works fine.
Has anyone experienced similar issues? What could be the problem?
Looking forward to hear any advice,
kind regards