Page 1 of 1
HTTP Status 415 “ Unsupported Media Type
Posted: Tue Sep 03, 2024 12:23 pm
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
Re: HTTP Status 415 “ Unsupported Media Type
Posted: Tue Sep 03, 2024 12:48 pm
by stefan@tageson.se
Your content-type is text/html but the payload seems to be json.
Eventually this can upset the server application.
Re: HTTP Status 415 “ Unsupported Media Type
Posted: Tue Sep 03, 2024 1:07 pm
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
Re: HTTP Status 415 “ Unsupported Media Type
Posted: Tue Sep 03, 2024 11:50 pm
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?
Re: HTTP Status 415 “ Unsupported Media Type
Posted: Thu Sep 19, 2024 9:22 am
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