This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

addFields

Class: matlab.net.http.Message
Package: matlab.net.http

Add fields to message header

Syntax

msg = addFields(msg,fields)
msg = addFields(msg,fName,fValue)
msg = addFields(msg,fName1,fValue1,...,fNameN,fValueN)
msg = addFields(msg,index,___)

Description

example

msg = addFields(msg,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 the RequestMessage 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.

msg = addFields(msg,fName,fValue) adds field with name fName and value fValue.

example

msg = addFields(msg,fName1,fValue1,...,fNameN,fValueN) adds fields specified by fName, fValue pair arguments, in the order specified.

example

msg = addFields(msg,index,___) inserts fields at index and can include any of the input arguments in previous syntaxes.

Input Arguments

expand all

Message, specified as a matlab.net.http.Message object.

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 for fName. To use the default value for the field, set fValue 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. If index is greater than the length of the header or index is 0, the method adds fields to the end. If index 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)
GET
Accept: text/plain

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

Introduced in R2016b