AL icon indicating copy to clipboard operation
AL copied to clipboard

AL code has an error message 'The format of value '1:e6c6699e-aa52-4cdc-b493-7f097fa53a9f' is invalid.'

Open monchangg opened this issue 7 years ago • 9 comments

I got following screenshot's error message when run following AL codes. image

`procedure GetToken() responseText: Text

var
    strUrl: Text;
    client: HttpClient;
    reqHeaders: HttpHeaders;
    request: HttpRequestMessage;
    response: HttpResponseMessage;
begin
    strUrl := 'https://APIAddress/token';
    request.SetRequestUri(strUrl);
    reqHeaders.Clear();
    request.GetHeaders(reqHeaders);
    request.Method := 'GET';
    reqHeaders.Add('authorization', '1:e6c6699e-aa52-4cdc-b493-7f097fa53a9f');
    client.Send(request, response);
    response.Content().ReadAs(responseText);

end;`

According to the error message, it is showed when executing AL code ' reqHeaders.Add('authorization', '1:e6c6699e-aa52-4cdc-b493-7f097fa53a9f');' It seems this issue is occured by 'authorization' key's value has special symbol colon ':'. Could anyone please help me how to resolve this colon issue?

monchangg avatar Dec 20 '18 07:12 monchangg

Does the code work when using the .NET HTTP client? What are the solutions there?

atoader avatar Dec 20 '18 12:12 atoader

Hi @atoader , yes, it works on .NET HTTP client. I want to call our web api and get token value through using AL HTTP client, but it throwed error message when add authorization value into HTTP header.

monchangg avatar Dec 21 '18 00:12 monchangg

@monchangg can you post the C# code that achieves the same goal you are trying to achieve in AL?

atoader avatar Dec 21 '18 06:12 atoader

@atoader Following is my C# code. `public string GetToken() {

        string path = @"https://APIAddress/token";
        HttpWebRequest request;
        HttpWebResponse response;
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
        request = WebRequest.Create(path) as HttpWebRequest;
        request.Method = "GET";
        request.KeepAlive = true;
        request.Accept = @"application/json";
        request.Headers.Add("authorization", "1:e6c6699e-aa52-4cdc-b493-7f097fa53a9f");            
        response = (HttpWebResponse)request.GetResponse();
        Stream stream = response.GetResponseStream();
        StreamReader reader = new StreamReader(stream, Encoding.UTF8);
        string result = reader.ReadToEnd();
        stream.Close();
        return result;
    }`

monchangg avatar Dec 24 '18 03:12 monchangg

Hi @atoader , do you have any solutions for my issue?

monchangg avatar Dec 27 '18 05:12 monchangg

Hi @atoader , can you please help me to look into my issue? I'm still waiting for your response.

monchangg avatar Jan 07 '19 08:01 monchangg

I apologize for the delay @monchangg! The AL HTTP classes are based on types in this namespace https://docs.microsoft.com/en-us/dotnet/api/system.net.http?redirectedfrom=MSDN&view=netframework-4.7.2 . The proper way to achieve this with HttpRequestMessage is to use TryAddWithoutValidation or by using TryAddWithoutValidation. I have opened a bug so that we add this for a future release.

atoader avatar Jan 07 '19 21:01 atoader

Hi @atoader , Thanks for your feedback. Could I know the release plan for fixing this issue?

monchangg avatar Jan 08 '19 01:01 monchangg

The fix for this issue has been checked in to the master branch. It will be available in the bcinsider.azurecr.io/bcsandbox-master Docker image starting from platform build number 27922.

If you don’t have access to these images you need to become part of the Ready2Go program: aka.ms/readytogo

For more details on code branches and docker images please read: https://blogs.msdn.microsoft.com/nav/2018/05/03/al-developer-previews-multiple-releases-and-github/ https://blogs.msdn.microsoft.com/freddyk/2018/04/16/which-docker-image-is-the-right-for-you/

ALGitHubBot avatar Feb 11 '19 11:02 ALGitHubBot