从Android应用程序我将数据发布到Heroku django解决方案。
但是django应用程序没有收到任何数据。
使用curl进行测试(insteat android app)我记录下这个日志:
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的本地工作正常。
答案 0 :(得分:4)
将更改网址解析到正确的位置:
http://myApp.herokuapp.com
代替
http://myApp.heroku.com