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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Unanswered

AX2009 bearer token - why I got empty authorization property in header?

(0) ShareShare
ReportReport
Posted on by 1,087

Hi everyone,

i'm trying to send a GET request with bearer token auth. The "parameters" of the request are pretty simple (for obious reasons i'm not typing the real host and token here..):

-host: "http://myhost.it/rest/V1/order/id?id=22"

-Authorization : "Bearer 116zjy7buwy80ax2s7id71ian9givs11"

-method: GET

-content type: "application/json"

static void job001(Args _args)
{
    System.Net.HttpWebRequest       request;
    System.IO.Stream                dataStream;
    System.Net.WebHeaderCollection  httpHeader;
    CLRObject                       clrObj;

    str                             token = "116zjy7bu1180a11s7id71ian9givs11";
    ;

    try
    {
        new InteropPermission(InteropKind::ClrInterop).assert();
        clrObj = System.Net.WebRequest::Create("http://myhost.it/rest/V1/order/id?id=22");

        httpHeader = new System.Net.WebHeaderCollection();

        httpHeader.Add("UserAgent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0");
        httpHeader.Add("Authorization", "Bearer "   token);
        httpHeader.Add("ContentType","Application/json");

        request = clrObj;
        request.set_Method("GET");

        request.set_Headers(httpHeader);
        
        //debug - begin
        httpHeader = request.get_Headers();
        info(httpHeader.ToString());        //1
        info(httpHeader.Get("Authorization"));  //2
        info(httpHeader.Get("UserAgent"));   //3
        //debug - end

        request.GetResponse();
    }
    catch(Exception::CLRError)
    {
        throw error(AifUtil::getClrErrorMessage());
    }
}

The host returns a "The remote server returned an error: (401) Unauthorized." error.

I've tried sending the same request via this site https://reqbin.com/ and it works perfectly.

So i did little more debugging and i asked to the host administrator to show me the header received from Ax 2009: the header looks like this:

Host: myhost.it

Contenttype: Application/json

Useragent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:75.0) Gecko/20100101 Firefox/75.0

Authorization:

Looks like the "Authorization" property gets empty once the request is made.

By the way, the debug section in my code prints out every property of the header and they are all filled properly. The "Authorization" property too.I've also tried "httpHeader.Set" instead of "httpHeader.Add"...same result.

I'm really having a hard time on this strange behaviour... any help would be really appreciated.

Thank you in advance

regards

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 523 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 408 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 354

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans