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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

sending data using in headers using REST POST method

(0) ShareShare
ReportReport
Posted on by 12

Hello All,

I am trying to send data using an external API. It needs the data to be sent in header itself. When I am trying to send the data. I get error message as 

Microsoft Dynamics NAV
---------------------------

A call to System.Threading.Tasks.Task`1[System.String].Result failed with this message: '"UTF-8"' is not a supported encoding name.
Parameter name: name
---------------------------
OK
---------------------------

Any help would be appreciated 

Thanks,

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Stefano Demiliani Profile Picture
    37,166 Most Valuable Professional on at

    How have you encoded the request message?

  • Sulav Thapaliya Profile Picture
    12 on at

    I used UTF8 encoding for this. Below is the code.

    stringContent := stringContent.StringContent(data,encoding.UTF8,'application/x-www-form-urlencoded');

  • Guillem Padilla Profile Picture
    427 on at

    Hello Sulav,

    Could you share with us how are you catching the response?

    Thanks

  • Suggested answer
    Suresh Kulla Profile Picture
    50,255 Super User 2026 Season 1 on at

    Share the code you are using to call the API

  • Sulav Thapaliya Profile Picture
    12 on at

    SMSSetup.GET;

    SMSSetup.TESTFIELD(SMSSetup."SMS API URL");

    SMSSetup.TESTFIELD("SMS Authentication Token");

    SMSSetup.TESTFIELD(Identity);

    IF GUIALLOWED THEN

     Window.OPEN(Text000);

    data := 'auth_token=' + SMSSetup."SMS Authentication Token";

    data += '&from=' + SMSSetup.Identity;

    data += '&to='+PhoneNo;

    data += '&text='+COPYSTR(MessageText,1,SMSSetup."SMS Text Length");

    stringContent := stringContent.StringContent(data,encoding.UTF8,'application/x-www-form-urlencoded');

    ReturnValue := CallRESTWebService(SMSSetup."SMS API URL",'',SMSSetup.Method,stringContent,HttpResponseMessage);

    result := HttpResponseMessage.Content.ReadAsStringAsync.Result;

    IF GUIALLOWED THEN

     Window.CLOSE;

    IF NOT ReturnValue THEN

     EXIT;

    result := HttpResponseMessage.Content.ReadAsStringAsync.Result;

    MESSAGE('%1',result.ToString);

    separator := ',';

    resultParts := result.Split(separator.ToCharArray());

    statusCode := FORMAT(result);

    ResponseCode := COPYSTR(statusCode,STRPOS(statusCode,'response_code') + 16,3);

    IF (ResponseCode = '200') THEN BEGIN

     EXIT(TRUE);

    END

    ELSE BEGIN

     EXIT(FALSE);

    END;

  • Suggested answer
    Muratvzr Profile Picture
    743 on at

    Here is the code for I am using for calling rest api HttpWebRequestMgt Codeunit great for this also if you want to deal with json you can use you can look at this blog post

    https://dynamics.is/?p=2637

    BodyPassword := STRSUBSTNO(bodyt,GlobApiKey);

    Url := STRSUBSTNO('%1/token',BaseUrl);

    HttpWebRequestMgt.Initialize(Url);

    HttpWebRequestMgt.DisableUI;

    HttpWebRequestMgt.SetMethod('POST');

    HttpWebRequestMgt.SetContentType('application/json');

    HttpWebRequestMgt.AddBodyAsAsciiText(BodyPassword);

    TempBlob.INIT;

    TempBlob.Blob.CREATEINSTREAM(Instr);

    IF NOT HttpWebRequestMgt.GetResponse(Instr,HttpStatusCode,ResponseHeaders) THEN

     HttpWebRequestMgt.ProcessFaultResponse('');

    IF HttpStatusCode.ToString <> HttpStatusCode.OK.ToString THEN

     ERROR('Connection Error');

  • Suggested answer
    Guillem Padilla Profile Picture
    427 on at

    Your code is sending charset correctly (charset=utf-8), it seems to be an error on API Response, surely the API is returning charset like this: charset=UTF8

    When you execute ReadAsStringAsync it validates the charset name (UTF8) and then you get the error.

    A workaround is to use ReadAsByteArrayAsync and parse the result.

    Share your progress with us :)

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans