如何删除 django 中 HttpResponse 返回的字符串中的 http 标头?
我正在尝试在 django 编写的 2 个后端之间构建一个 Web 服务系统。但是,即使将 HttpResponse 更改为 json 类型后:
HttpResponse('{"operation":"done"}',mimetype='application/json'
)
我仍然在另一个中获取 http 标头信息django machine:
{u'body': u'{"myjson":"here"}', u'headers': {'status': 200, 'content-length': '235', 'server': 'Google Frontend', 'cache-control': 'private, x-gzip-ok=""', 'date': 'Thu, 05 May 2011 06:16:16 GMT', 'content-type': 'application/json'}}
标头信息对我来说根本不需要。有什么方便的方法可以去掉吗?
[编辑] 我用来执行restFUL请求的库是: http://code.google .com/p/python-rest-client/wiki/Using_Connection
谢谢
I am trying to build a web service system between 2 back-end written in django. However, even after changing the HttpResponse to json type:
HttpResponse('{"operation":"done"}',mimetype='application/json'
)
I still get the http header information in the other django machine:
{u'body': u'{"myjson":"here"}', u'headers': {'status': 200, 'content-length': '235', 'server': 'Google Frontend', 'cache-control': 'private, x-gzip-ok=""', 'date': 'Thu, 05 May 2011 06:16:16 GMT', 'content-type': 'application/json'}}
The header information is simply not necessary for me. Is there any convenient way to strip it?
[Edited]
The lib I use to conduct restFUL request is: http://code.google.com/p/python-rest-client/wiki/Using_Connection
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我终于发现返回的响应是一个集合类型:
如果你用上面的函数获取响应,你在这里得到的值实际上是一个地图。
然后,您只需使用以下命令即可访问响应的正文部分:
问题已解决。响应的标头部分不再是问题。
[编辑]
愚蠢的我。它只是在文档中指定:
http://code.google.com/p/python-rest-client /wiki/Using_Connection
I finally discovered that returned response is a collection type:
If you take the response with the function above, the value you get here is actually a map.
Then you are able to access the body part of the response simply with:
Problem solved. The header part of the response is no longer an issue.
[Edited]
Silly me. It's just specified in the doc:
http://code.google.com/p/python-rest-client/wiki/Using_Connection