415 UNSUPPORTED MEDIA TYPE - indy idHttp

Hello Guys,

Using indy when I try to post my code json to the serve, I got the follwing message:

415 UNSUPPORTED MEDIA TYPE

Where is the problem? The way that Json was created? Any declaration that I forgot?

I appreciate a lot any help on this


procedure TForm1.Button3Click(Sender: TObject);
var
  PostData: TStringList;
  JsonStreamRetorno, JsonStreamEnvio: TStringStream;
  rta, json: string;
begin

  JsonStreamRetorno := TStringStream.Create('');
  JsonStreamEnvio   := TStringStream.Create('{"nome": "AlexandreTeste",' +
                                            '"amb_uuid": "c75831f0-4561-4de8-b722-dd82f06f7a01",' +
                                            '"email_admin": "Alexandregarcia@khan.com.br"}');

  IdHTTP1.Request.Clear;
  IdHTTP1.Request.CustomHeaders.Add('Authorization:ace49f940a034ea4a35c8157d4620c3a');
  idHttp1.Response.ContentType := 'application/json';
  idHttp1.Response.CharSet := 'UTF-8';

  try
     IdHTTP1.Post( 'https://khanhomolog.skyinone.net/v2/api/clients/' , JsonStreamEnvio, JsonStreamRetorno);
   finally
    PostData.Free;
  end;

  Memo1.Lines.add( JsonStreamRetorno.DataString )

end;

Open in new window


Alex
LVL 1
hidrauAsked:
Who is Participating?
 
hidrauAuthor Commented:
I figured out the problem, it was here:

idHttp1.Response.ContentType := 'application/json';

I changed to:

  IdHTTP1.Request.ContentType  := 'application/json';
0
 
KimputerCommented:
Try without the
  idHttp1.Response.CharSet := 'UTF-8';
0
 
hidrauAuthor Commented:
the same message :(

You can try with my code to get the success.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

 
ste5anSenior DeveloperCommented:
Check the server side... maybe the have a buggy REST service.. some require

application/json;charset=utf-8

Open in new window

as content type.
0
 
hidrauAuthor Commented:
The same message
0
 
ste5anSenior DeveloperCommented:
Well, just run a Fiddler sessions to compare a working request with yours.

Caveat: Use Fiddler only on development machines.
0
 
hidrauAuthor Commented:
I am trying to find an example in delphi using idhttp.post with json to see it is working. Maybe using the google api. Do you have any ideia?
0
 
ste5anSenior DeveloperCommented:
Just ask the owner of

https://khanhomolog.skyinone.net/v2/api/clients/

for a working wget example (these are the minimum documentation samples).
0
 
hidrauAuthor Commented:
thanks a lot for your help
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.