【发布时间】:2012-06-03 22:27:18
【问题描述】:
我正在从一个 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
好像是redirect的问题,好像curl(android)在redirect操作后没有发送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 可以正常工作。
【问题讨论】:
标签: android django heroku http-post