Main Content

matlab.net.http.field.AcceptField Class

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

HTTP Accept header field

Description

An AcceptField object is an HTTP header field in a request message. The field contains one or more media type specifications indicating the type of content acceptable to the client. For a description of this field, see RFC 7231 Semantics and Content, section 5.3.2 Accept on the RFC Editor website.

Class Attributes

Sealed
true

For information on class attributes, see Class Attributes.

Creation

Description

obj = matlab.net.http.field.AcceptField(value) creates an Accept header field with the Value property set to value.

Use an Accept field if the server can return different MediaType objects and you want to receive only certain types. If you do not specify an Accept field, the server might assume that you are willing to receive any type.

example

Properties

expand all

Header field name, specified as 'Accept'.

Attributes:

GetAccess
public
SetAccess
public

Media type, specified as a vector of matlab.net.http.MediaType objects, a vector of strings, or a cell array of character vectors. All strings must be acceptable to the MediaType constructor. Each Value represents a media type containing an optional quality ('q') parameter. The Value property of the field is a comma-separated list of the MediaType objects converted to strings.

Example: MediaType('application/json','q','.5')

Attributes:

GetAccess
public
SetAccess
public
Dependent
true

Methods

expand all

Examples

collapse all

This example shows how a client specifies media type image/jpeg for reading an image.

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

httpUrl  = 'http://requestserver.mathworks.com';
uri = URI(strcat(httpUrl, '/assets/computerVision.jpg'));
headers = AcceptField(MediaType('image/jpeg')); 
req = RequestMessage('GET', headers);
[~, completedReq, ~] = req.send(uri);
show(completedReq, 0)
GET /assets/computerVision.jpg HTTP/1.1
Host: requestserver.mathworks.com
Accept: image/jpeg
User-Agent: MATLAB/9.11.0.1650920 (R2021b) Prerelease
Date: Wed, 28 Apr 2021 14:33:47 GMT
Accept-Encoding: gzip

Version History

Introduced in R2016b