Main Content

matlab.net.http.field.ContentLengthField 类

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

HTTP Content-Length 字段

描述

ContentLengthField 对象是请求消息或响应消息中的 HTTP 标头字段,它以字节为单位指定有效负载的长度。

MATLAB® 要求所有带有效负载的出站消息都必须包含一个 Content-Length 字段。如果消息中包含非空主体,则 MATLAB 将根据数据的长度创建一个 Content-Length 字段。但是,对于分块数据传输,不添加任何字段。有关详细信息,请参阅 Internet Engineering Task Force (IETF®) 网站上的 RFC 7231, section 3.3.2.Content-Length。

响应消息可能包含,也可能不包含此字段。

类属性

Sealed
true

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

创建对象

描述

示例

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

属性

全部展开

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

属性:

GetAccess
public
SetAccess
public

有效负载的长度(以字节为单位),指定为非负整数或计算结果为非负整数的字符串。

属性:

GetAccess
public
SetAccess
public
Dependent
true

方法

全部展开

示例

全部折叠

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

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);
contentLengthField = response.getFields("Content-Length");
disp(contentLengthField)
  ContentLengthField with properties:

     Name: "Content-Length"
    Value: "102297"

版本历史记录

在 R2016b 中推出