Error in rest service like "authorization 301 error" in ax 2012

Hi,

How to consume the rest api in ax 2012.

I have tried the below code but i getting error like "Authorization 301 error" in response line.

How to resolve the error

static void ODataservice(Args _args)  
 {  
   
   System.Net.HttpWebRequest    request;  
   System.Net.HttpWebResponse   response;  
   CLRObject            clrObj;  
   System.Byte[]          bytes;  
   System.Text.Encoding      utf8;  
   System.IO.Stream        requestStream, responseStream;  
   System.IO.StreamReader     streamReader;  
   System.Exception        ex;  
   System.Net.WebHeaderCollection httpHeader;  
   str               byteStr;  
   System.Byte[]          byteArray;  
   System.IO.Stream        stream;  
   System.IO.Stream        dataStream;  
   byteStr = strfmt('%1:%2', "USERNAME", "PASSWORD");  
  
   try  
   {  
     new InteropPermission(InteropKind::ClrInterop).assert();  
     httpHeader = new System.Net.WebHeaderCollection();  
     clrObj = System.Net.WebRequest::Create(url);  
     request = clrObj;  
     utf8 = System.Text.Encoding::get_UTF8();   
     request.set_KeepAlive(true);  
     request.set_ContentType("application/xml");  
     utf8    = System.Text.Encoding::get_UTF8();  
     byteArray  = utf8.GetBytes(byteStr);  
     byteStr   = System.Convert::ToBase64String(byteArray);  
     httpHeader.Add("Authorization", 'Basic ' + byteStr);  
     request.set_ContentType("text/xml; encoding='utf-8'");   
     request.set_Method("POST");  
     request.set_Headers(httpHeader);  
     requestStream = request.GetRequestStream();   
     response = request.GetResponse();  
     responseStream = response.GetResponseStream();  
     streamReader = new System.IO.StreamReader(responseStream);  
     responseXml = streamReader.ReadToEnd();  
     info(responseXml);  
   }  
   catch (Exception::CLRError)  
   {  
     //bp deviation documented  
     ex = CLRInterop::getLastException().GetBaseException();  
     error(ex.get_Message());  
   }  
   requestStream.Close();  
   streamReader.Close();  
   responseStream.Close();  
   response.Close();  
 }  
Related
Recommended