Main Content

matlab.net.http.field.ContentTypeField 类

命名空间: matlab.net.http.field
超类: matlab.net.http.HeaderField, matlab.net.http.field.MediaRangeField

HTTP Content-Type 标头字段

描述

ContentTypeField 对象是请求消息或响应消息中的 HTTP 标头字段。此字段包含一个媒体类型设定,指示消息主体中的内容类型。有关详细信息,请参阅 Internet Engineering Task Force 网站上的 RFC 7231 Semantics and Content, section 3.1.1.5.Content-Type。

在请求消息中,Content-Type 字段决定如何转换 MessageBody.Data 属性中指定的数据。有关此转换的信息,请参阅HTTP Data Type Conversion。如果请求消息包含非空主体,但不包含 Content-Type 字段,MATLAB® 将根据数据类型创建一个 Content-Type 字段。

类属性

Sealed
true

有关类属性的信息,请参阅类属性

创建对象

描述

示例

obj = matlab.net.http.field.ContentTypeField(value) 创建一个 Content-Type 标头字段,并将 Value 属性设置为 value

属性

全部展开

标头字段名称,指定为 'Content-Type'

属性:

GetAccess
public
SetAccess
public
Dependent
true

媒体类型,指定为 matlab.net.http.MediaType 对象或者可被 MediaType 构造函数接受的字符串。Value 不能包含质量 ('q') 参数。

示例: 'text/html;charset=utf-8'

属性:

GetAccess
public
SetAccess
public

方法

全部展开

示例

全部折叠

此示例说明如何读取消息中的 Content-Type 字段。

import matlab.net.*;
import matlab.net.http.*;

httpsUrl = 'https://requestserver.mathworks.com';
uri = URI(strcat(httpsUrl, '/assets/computerVision.jpg'));
req = RequestMessage('GET');
response = req.send(uri);
contentTypeField = response.getFields("Content-Type");
disp(contentTypeField)
  ContentTypeField with properties:

     Name: "Content-Type"
    Value: "image/jpeg"

版本历史记录

在 R2016b 中推出