HTTP Status 415 “ Unsupported Media Type

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
MarioM
Posts: 3
Joined: Thu Sep 02, 2021 10:37 am
Location: Italy

HTTP Status 415 “ Unsupported Media Type

Post by MarioM »

Hello
It is my first project about consumig a REST webservice with JSON. I use HTTPAPI+YAJL for my program. When I call it I receive the error
HTTP Status 415 – Unsupported Media Type . I did a search on web for this error and I understand that the server doesn't undestand my request but I don't understand why. Attached I put the debug log.Is there anyone that can help me?

Thanks
Mario
Attachments
CntFat-diagnostic-log (1).zip
(3.73 KiB) Downloaded 472 times
stefan@tageson.se
Posts: 23
Joined: Wed Jul 28, 2021 7:55 am
Location: Viken, Sweden
Contact:

Re: HTTP Status 415 “ Unsupported Media Type

Post by stefan@tageson.se »

Your content-type is text/html but the payload seems to be json.
Eventually this can upset the server application.
MarioM
Posts: 3
Joined: Thu Sep 02, 2021 10:37 am
Location: Italy

Re: HTTP Status 415 “ Unsupported Media Type

Post by MarioM »

After I post the question I was able to speak to the server side manager who told me that I have to send a Content-Type “multipart/form-data” instead of “application/json" . Besides he told me that now in the body of the request there is a unique JSON with all fields while should be so many multipart each with his key/value. Is it possible with YAJL and how?
Thank in advance
Mario
Scott Klement
Site Admin
Posts: 872
Joined: Sun Jul 04, 2021 5:12 am

Re: HTTP Status 415 “ Unsupported Media Type

Post by Scott Klement »

MarioM wrote: Tue Sep 03, 2024 1:07 pm Besides he told me that now in the body of the request there is a unique JSON with all fields while should be so many multipart each with his key/value. Is it possible with YAJL and how?
I'm sorry, but I don't understand what you're asking.

HTTPAPI supports creating multipart/form-data documents by using the "MFD encoder" routines (MFD means Multipart/Form-Data). So you will find routines named http_mfd_encoder_open(), http_mfd_encoder_addvar(), http_mfd_encoder_addstmf(), http_mfd_encoder_addvar_s(), and http_mfd_encoder_close(). These are used to create a multipart/form-data document.

If you want one or more parts of that multipart form to be JSON documents, you can create the documents with YAJL, and then add them using the addvar() or addstmf() routines mentioned above.

But, what does "JSON with all fields while should be so many multipart each with his key/value" mean? I don't understand what you mean by that. Can you provide an example?
MarioM
Posts: 3
Joined: Thu Sep 02, 2021 10:37 am
Location: Italy

Re: HTTP Status 415 “ Unsupported Media Type

Post by MarioM »

Hi Scott
you are right about JSON and multipart but the server side told me that they use JSON, instead of multipart . However I used your http_mfd_encoder* routine and was able to solve the error.
Thanks
Mario
Post Reply