Skip to main content

Notifications

Announcements

No record found.

Business Central forum
Unanswered

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

Posted on by 49
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 49 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.
  • Rajaneesh H Profile Picture
    Rajaneesh H 49 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 14,584 User Group Leader 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

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,773 Super User

#2
Martin Dráb Profile Picture

Martin Dráb 225,513 Super User

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans