Skip to content
Advertisement

415 UNSUPPORTED MEDIA – API Post Javascript – Django

I am trying to create an API on my Django server but I am struggling to create a post method called by Javascript.

This is my APIview

class componentFrameAPI(APIView):

JavaScript

And this is my post request on Javascript.

JavaScript

I continue to receive a 415 error and I really don’t know what I am doing wrong.

NOTE: The GET method works fine.

Thanks for your help.

Giacomo

Advertisement

Answer

Your are close but have a typo in xhttp.setRequestHeader('contentType', 'application/json')

Change that to

JavaScript

And you should be fine Full example

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement