从一个 android 应用程序我将数据发布到 Heroku django 解决方案。
但是 django 应用程序没有收到任何数据。
使用 curl(insteat android 应用程序)测试我记录了这个日志:
dani@heroku-test:~/tmp$ curl -vd '[{"lat ____some data ___ adf"}]' \
http://myApp.heroku.com/x/receive_JSON/
* About to connect() to myApp.heroku.com port 80 (#0)
* Trying 107.21.106.77... connected
> POST /x/receive_JSON/ HTTP/1.1
> User-Agent: curl/7.22.0 (i686-pc-linux-gnu)
libcurl/7.22.0 OpenSSL/1.0.1 zlib/1.2.3.4 libidn/1.23 librtmp/2.3
> Host: myApp.heroku.com
> Accept: */*
> Content-Length: 296 <---- OK!!!
> Content-Type: application/x-www-form-urlencoded
>
* upload completely sent off: 296out of 296 bytes
< HTTP/1.1 301 Moved Permanently
< Server: nginx
< Date: Sun, 03 Jun 2012 22:15:13 GMT
< Connection: keep-alive
< Location: http://myApp.herokuapp.com/x/receive_JSON/
< Content-Length: 0 <-----KO!!!!!!!!!!!!!!!!!!!!!!!!!!
<
* Connection #0 to host myApp.heroku.com left intact
* Closing connection #0
似乎是重定向的问题,似乎 curl (android) 在重定向操作后不发送 POST 数据。
我该如何解决此问题或可能有什么解决方法?
我的 Django 视图来测试接收到的数据:
@csrf_exempt
def receive_JSON(request ):
return HttpResponse("Rebut: {0}".format( len( request.raw_post_data ) ) )
要发送数据,我使用How to send a JSON object over Request with Android? (还有 httpost.setHeader("Content-type", "application/json"); )
注意:这在本地使用 runserver 可以正常工作。