Reputation: 6836
I'm writing a Rest Framework view for receiving a JSON POST request. However, the incoming request has no Content-Type header (valid HTTP), and as documented, Rest Framework throws an UnsupportedMediaType
and returns a 415 Unsupported Media Type
.
I do not control the client. How can I force the request to processed with JSONParser
despite no declared content type? (perhaps I can access the underlying request before processing by the parsers?)
Here's is my current (simple) view:
class Callback(APIView):
# this doesn't help
# parser_classes = (JSONParser,)
def post(self, request, format=None):
# ...operate on request.DATA
Upvotes: 2
Views: 1241
Reputation: 33901
Take a look at writing a custom content negotiation class.
http://www.django-rest-framework.org/api-guide/content-negotiation#custom-content-negotiation
You'll want to base it on the default implementation, but returning JSONParser
if nothing else matches.
Upvotes: 2