Content-Type: application/json leads to BAD REQUEST

Anonymous avatarAnonymous created an issue

if I try to POST Json data to my application I always get a BAD REQUEST (normal key-value pairs work just fine).

My looks:

class CsrfExemptResource(Resource): """A Custom Resource that is csrf exempt""" def init(self, handler, authentication=None): super(CsrfExemptResource, self).init(handler, authentication) self.csrf_exempt = getattr(self.handler, 'csrf_exempt', True)

my_handler = CsrfExemptResource(MyHandler)

urlpatterns = patterns('', url(r'^resource$', recipe_handler) )

My Handler:

class MyHandler(AnonymousBaseHandler): def create(self, request): if request.content_type: data = title=data['title'] return title else: return "something went wrong"

This is how I send the data to the application:

curl -i -X POST -H 'Content-Type:application /json' -X POST -d "{"content": "test", "comments": [{"content": "test1"}, {"content": "test2"}], "title": "test"}" http://localhost/api/resource

The result:

HTTP/1.1 400 BAD REQUEST Date: Wed, 27 Oct 2010 09:30:12 GMT Server: Apache/2.2.14 (Ubuntu) Vary: Authorization,Accept-Encoding Connection: close Transfer-Encoding: chunked Content-Type: text/plain

What I find confusing, the result says "Content-Type: text/plain" but I defined "Content-Type:application /json"

Comments (0)

  1. Log in to comment
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.