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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
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
Python 3 Fundamentals

This course will teach participants about installing and configuring Python, syntax, importing, statements, types, strings, booleans, files, lists, tuples, comprehensions, functions, and classes.

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:
I figured out the problem, it was here:

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

I changed to:

  IdHTTP1.Request.ContentType  := 'application/json';
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
hidrauAuthor Commented:
thanks a lot for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.