Main Content

matlab.net.http.field.ContentLengthField Class

Namespace: matlab.net.http.field
Superclasses: matlab.net.http.HeaderField, matlab.net.http.field.IntegerField

HTTP Content-Length field

Description

A ContentLengthField object is an HTTP header field in a request or a response message that specifies the length of the payload in bytes.

MATLAB® requires all outbound messages with a payload to contain a Content-Length field. If a message contains a nonempty body, then MATLAB creates a Content-Length field based on the length of the data. However, for chunked data transfers, no field is added. For more information, see RFC 7231, section 3.3.2. Content-Length on the RFC Editor website.

Response messages might or might not contain this field.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

obj = matlab.net.http.field.ContentLengthField(value) creates a Content-Length header field with the Value property set to value.

example

Properties

expand all

Header field name, specified as 'Content-Length'.

Attributes:

GetAccess
public
SetAccess
public

Length of payload in bytes, specified as a nonnegative integer or a string that evaluates to a nonnegative integer.

Attributes:

GetAccess
public
SetAccess
public
Dependent
true

Methods

expand all

Examples

collapse all

This example shows how to read the Content-Length field in a message.

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"

Version History

Introduced in R2016b