简体   繁体   English

当内容类型没有在http中发送时会出现什么问题?

[英]What issues are there when content-type not sent in http?

What issues are there when content-type not sent in an httpresponse header? 在httpresponse标头中未发送内容类型时会出现什么问题? Specifically what happens to JSON types like the one below if content_type is omitted? 具体来说,如果省略content_type,JSON类型会发生什么?

class JSONResponse(HttpResponse):
"""
An HttpResponse that renders its content into JSON.
"""
def __init__(self, data, **kwargs):
    content = JSONRenderer().render(data)
    kwargs['content_type'] = 'application/json'
    super(JSONResponse, self).__init__(content, **kwargs)

According to HTTP spec content-type should be passed as one of the headers, there is no "default value". 根据HTTP规范,content-type 作为其中一个头传递,没有“默认值”。 If the client does not implement it - it's up to the server's implementation to decide what to return in the response. 如果客户端没有实现它 - 由服务器的实现决定在响应中返回什么。 See last section of 7.2.1 7.2.1的最后一

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM