Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Answered

Reg: MIME type could not be found that matches the content type of the response

Posted on by 175
Hi Techis,

I am working on POSTing a JSON value to the Business Central.

I am getting below error message



My code looks like below

var
                    http_req_mes: HttpRequestMessage;
                    http_cont: HttpContent;
                    http_clnt: HttpClient;
                    http_resp: HttpResponseMessage;
                    outputstring: Text;

                begin

                    http_req_mes.SetRequestUri('http://xxxxTestUsersRaj');
                    http_req_mes.Method := 'Post';

                    http_cont.WriteFrom(GeneratePayload());
                    http_req_mes.Content(http_cont);
                    http_clnt.UseWindowsAuthentication('xxx', xxxx');

                    if http_clnt.Send(http_req_mes, http_resp) then
                        if http_resp.IsSuccessStatusCode then begin
                            http_resp.Content.ReadAs(outputstring);
                            Message(Format(outputstring));
                        end else
                            Message('Error %1', http_resp.ReasonPhrase);
                end;

Also, I investigated that in POSTMAN in the ‘Body’ tab, if I don’t select the JSON in drop down same error occurs.



Let me know how I pass the above value in AL code.

Thanks
 
  • Rajaneesh H Profile Picture
    Rajaneesh H 175 on at
    Reg: MIME type could not be found that matches the content type of the response
    Thanks Saurav for your response!!
     
    I am big fan of you!! I love all your articles/videos/blogs related to BC.
  • Verified answer
    Rajaneesh H Profile Picture
    Rajaneesh H 175 on at
    Reg: MIME type could not be found that matches the content type of the response
    Hi Techis,
     
    I have fixed above issue by adding the below code.
     
                        http_cont.GetHeaders(contenthdr);
                        if contenthdr.Contains('Content-Type') then contenthdr.Remove('Content-Type');
                        contenthdr.Add('Content-Type', 'application/json');
     
    Hope this might help someone like me!
     
    Happy Coding!
  • Saurav.Dhyani Profile Picture
    Saurav.Dhyani 17,957 Super User 2024 Season 2 on at
    Reg: MIME type could not be found that matches the content type of the response
    Hi,
     
    I didn't get the question completely. 
     
    But it seems you are not passing header to be in content header. 
     
    contentHeaders.Add('Content-Type', 'application/json');
     

    We are doing a series on API; you can watch it in YouTube - https://www.youtube.com/watch?v=AvJCkc0Xhxw
     
     
    We will be discussing your area going forward in same series.
     
     
    Regards,
    Saurav Dhyani

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans