Skip to main content

Notifications

Announcements

No record found.

Small and medium business | Business Central, N...
Answered

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

Posted on by 182
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 182 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 182 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,965 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

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,214 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans