matlab.net.http.Message.addFields - Add fields to message header - MATLAB (original) (raw)

Class: matlab.net.http.Message
Namespace: matlab.net.http

Add fields to message header

Syntax

Description

msg = addFields([msg](#ref%5Fq3fxxdhn41%5Fsep%5Fshared-msg),[fields](#ref%5Fq3fxxdhn41-fields)) adds fields to the end of the header of each message and returns the updated message.

addFields does not check for duplicate fields, but theRequestMessage send and complete methods might reject inappropriate duplicates.

To prevent the send or complete methods from automatically adding a particular header field, call addFields for that field with an empty ([]) Value property.

example

msg = addFields([msg](#ref%5Fq3fxxdhn41%5Fsep%5Fshared-msg),[fName](#ref%5Fq3fxxdhn41-fName),[fValue](#ref%5Fq3fxxdhn41-fValue)) adds field with name fName and valuefValue.

msg = addFields([msg](#ref%5Fq3fxxdhn41%5Fsep%5Fshared-msg),fName1,fValue1,...,fNameN,fValueN) adds fields specified by fName, fValue pair arguments, in the order specified.

example

msg = addFields([msg](#ref%5Fq3fxxdhn41%5Fsep%5Fshared-msg),[index](#ref%5Fq3fxxdhn41-index),___) inserts fields at index and can include any of the input arguments in previous syntaxes.

example

Input Arguments

expand all

Fields to add, specified as a vector or comma-separated list of one or more matlab.net.http.HeaderField objects.

Example: matlab.net.http.HeaderField('Accept','text/plain')

Header field name, specified as a string.

Example: 'Accept'

Header field value, specified as a string or any type valid forfName. To use the default value for the field, setfValue to ''. If the last value is missing, then it is the same as specifying [].

Example: 'text/plain'

Location in the message header, specified as an integer. Ifindex is greater than the length of the header orindex is 0, the method adds fields to the end. Ifindex is negative, the method counts from the end of the header.

Example: -1 inserts fields before the last field

Examples

expand all

Create an Accept header field with value 'text/plain' and add it to a default request message.

field = matlab.net.http.HeaderField('Accept','text/plain'); m = matlab.net.http.RequestMessage('get'); msg = addFields(m,field); show(msg)

Add two header fields to a request message.

m = matlab.net.http.RequestMessage('get'); msg = addFields(m,'Accept','text/plain','Cache-Control','no-store, no-cache'); show(msg)

GET Accept: text/plain Cache-Control: no-store, no-cache

Create a request message with two header fields.

m = matlab.net.http.RequestMessage('get'); msg = addFields(m,'Accept','text/plain','Cache-Control','no-store, no-cache');

Insert a Content-Type header field before the last header field in a message.

f = matlab.net.http.HeaderField('Content-Type','text/plain'); msg = addFields(msg,-1,f); show(msg)

GET Accept: text/plain Content-Type: text/plain Cache-Control: no-store, no-cache

Version History

Introduced in R2016b