获取内容请求类型 [英] Get Content Type of Request

查看:266
本文介绍了获取内容请求类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

要查找传入的内容类型,请文档说明

To find the incoming content type, docs say:

 request.headers["Content-Type"] # => "text/plain"

但我通过反复试验发现,这不起作用,但这样做:

But I found by trial-and-error, that doesn't work, but this does:

 request.headers["CONTENT_TYPE"]=='application/json'

那么最强大+便携的方式是什么?

So what's the most robust+portable way to do it?

推荐答案

我通常会去 request.format request.content_type 来阅读这些标题字段。

I would usually go for request.format and request.content_type for reading these header fields.

编辑:在此基础上找到更多信息可能有所帮助: https://stackoverflow.com/a/1595453/624590

EDIT: found a bit more on this that might help: https://stackoverflow.com/a/1595453/624590

这篇关于获取内容请求类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆