How do I remove the http header in the string returned by HttpResponse in django?
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':开发者_如何学Go {'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
I finally discovered that returned response is a collection type:
def getSOAResponse(soa, uri, parameters):
conn = Connection(soa)
value = conn.request_get(uri, args=parameters)
return value
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:
body = value['body']
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
精彩评论