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
HTTP Status 415 “ Unsupported Media Type
HTTP Status 415 “ Unsupported Media Type
- Attachments
-
- CntFat-diagnostic-log (1).zip
- (3.73 KiB) Downloaded 471 times
-
- Posts: 23
- Joined: Wed Jul 28, 2021 7:55 am
- Location: Viken, Sweden
- Contact:
Re: HTTP Status 415 “ Unsupported Media Type
Your content-type is text/html but the payload seems to be json.
Eventually this can upset the server application.
Eventually this can upset the server application.
Re: HTTP Status 415 “ Unsupported Media Type
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
Thank in advance
Mario
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: HTTP Status 415 “ Unsupported Media Type
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
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
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