带有 XML 数据的 HTTP POST 在 Django-Piston 中不起作用
我已经使用 django 活塞实现了 API,其中它从 sms/mms
获取数据。对于 MMS 情况,我必须发布带有图像和其他内容的 XML 数据。这是我在 handlers.py 上的代码片段,
def create(self, request,*args,**kwagrs):
try:
file_type = None
raw_data = request.raw_post_data
data = serializers.deserialize("xml", raw_data)
try:
parser = Parse(data.stream.getvalue())
message = parser.get_message()
action_id = parser.get_action_id()
except Exception,e:
return HttpResponse(Response({'sender':parser.get_sender(),'error_description':str(e)}).get_error_response(), mimetype='text/xml')
if action_id in ['o','m','vt','vh','yritys']:
return self.post_message(request,parser)
elif action_id == 'poista' or action_id == 'lopeta':
return self.expired_message(request,parser)
elif action_id == 'tiedot':
return self.get_contact_info(request,parser)
except Exception,e:
ad_id = None
return HttpResponse(Response({'sender':parser.get_sender(),'error_description':str(e)}).get_error_response(), mimetype='text/xml')
当我使用 CURL
发布 xml 数据
时,它可以正常工作,但是当我使用 Firefox
时,httprequester
它抛出了我“BAD REQUEST”
I have implemented API with django piston in which its take data from sms/mms
. For MMS case i have to post XML data with image and others . Here is my code snippet on handlers.py
def create(self, request,*args,**kwagrs):
try:
file_type = None
raw_data = request.raw_post_data
data = serializers.deserialize("xml", raw_data)
try:
parser = Parse(data.stream.getvalue())
message = parser.get_message()
action_id = parser.get_action_id()
except Exception,e:
return HttpResponse(Response({'sender':parser.get_sender(),'error_description':str(e)}).get_error_response(), mimetype='text/xml')
if action_id in ['o','m','vt','vh','yritys']:
return self.post_message(request,parser)
elif action_id == 'poista' or action_id == 'lopeta':
return self.expired_message(request,parser)
elif action_id == 'tiedot':
return self.get_contact_info(request,parser)
except Exception,e:
ad_id = None
return HttpResponse(Response({'sender':parser.get_sender(),'error_description':str(e)}).get_error_response(), mimetype='text/xml')
when I am posting xml data
with CURL
its working , but when i use Firefox
, httprequester
its throwing me "BAD REQUEST"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
检查一下:
我在使用 django 时收到 400 错误请求错误-piston
创建中间件为:
将其添加到设置中:
MIDDLEWARE_CLASSES = (
'app.middleware.ContentTypeMiddleware',
)
Check this:
I get a 400 Bad Request error while using django-piston
Create middleware as:
Add it in settings:
MIDDLEWARE_CLASSES = (
'app.middleware.ContentTypeMiddleware',
)
尝试 hurl.it 进行 API 测试。检查您的帖子数据。如果需要,设置您的标题信息。
Try hurl.it for API testing. Check your post data. Set your header info if required.