Main Content

replaceFields

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

Change values in or add fields to message header

Description

msg = replaceFields(msg,FieldName1,FieldValue1,...,FieldNameN,FieldValueN)replaces fields with the specified names to the indicated values specified in FieldName1,FieldValue1,...,FieldNameN,FieldValueN and returns the updated message.

This method is the same as the changeFields method, but if a field does not exist which matches the name or class, then the method adds a new one to the end of the header instead of throwing an error.

msg = replaceFields(msg,newFields) replaces the existing fields in each message to the names, values, and types specified in newFields and returns the updated message.

Input Arguments

expand all

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

Fields defined by name-value pairs. FieldName is specified as a string or character vector, and FieldValue is specified as any type valid for FieldName.

To use the default value for the field, set FieldValue to ''.

If the last value is missing, it is the same as specifying empty ([]).

Names to match, specified as one of the following.

  • String vector, character vector, cell array of character vectors, or comma-separated list of strings or character vectors containing the names of the fields to replace. Names are not case-sensitive.

  • Vector or comma-separated list of one or more HeaderField objects whose Name properties are used to determine which fields to replace. Names are not case-sensitive. Header field values are ignored.

  • Vector or comma-separated list of matlab.metadata.Class objects that are subclasses of HeaderField.

    The replaceFields method searches for names that match names supported by the specified classes, regardless of the class. If a subclass does not have a specific set of supported names, all header fields of that subclass are matched regardless of their names. Call the HeaderField.displaySubclasses method to see supported names.

Version History

Introduced in R2016b