matlab.net.http.Message.changeFields - Change existing fields in message header - MATLAB (original) (raw)
Main Content
Class: matlab.net.http.Message
Namespace: matlab.net.http
Change existing fields in message header
Syntax
Description
msg = changeFields([msg](#ref%5Fq3fxxdhxv3%5Fsep%5Fshared-msg),[fields](#ref%5Fq3fxxdhxv3-fields))
changes the existing fields in each message to the names, values, and types specified infields
and returns the updated message. This syntax might change the class of an existing field if the field name is a case-insensitive match to a name infields
.
This method throws an error when:
- All the specified fields are not already in the header.
- There is more than one field with the specified name.
msg = changeFields([msg](#ref%5Fq3fxxdhxv3%5Fsep%5Fshared-msg),[FieldName1,FieldValue1,...,FieldNameN,FieldValueN](#ref%5Fq3fxxdhxv3-FieldName1FieldValue1FieldNameNFieldValueN))
changes fields with the specified names to the indicated values.
Name matching is case-insensitive. However, if you specify a name that differs in case from the existing field name, then the field name changes to the specified name. This usage does not change the class of an existing field.
Input Arguments
Fields to change, specified as a vector or comma-separated list of one or morematlab.net.http.HeaderField
objects.
Example: 'Accept','text/plain'
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 ([]
).
Examples
Create two Content-Length fields using the HeaderField
class and its subclass, ContentLengthField
. Change the value of the Content-Length field in a message, which changes the class of the field, depending on how you create the original header field.
Create two header files with the same properties. The fields have the same value, but the classes are different.
h1 = matlab.net.http.HeaderField('Content-Length',5); h2 = matlab.net.http.field.ContentLengthField(5); compareNames = eq(h1.Name,h2.Name)
compareValues = eq(h1.Value,h2.Value)
compareValues = logical 1
Create a request message using the h1
header field and display its class.
r = matlab.net.http.RequestMessage; r.Header= h1; h1Class = class(r.Header)
h1Class = 'matlab.net.http.HeaderField'
Change the Content-Length header field using the h2
header field. The header field class changes.
r1 = r.changeFields(h2); h2Class = class(r1.Header)
h2Class = 'matlab.net.http.HeaderField'
Change the Content-Length header field using a name-value pair. The header field class does not change.
r1 = r.changeFields('Content-length',5); class(r1.Header)
ans = 'matlab.net.http.HeaderField'
Version History
Introduced in R2016b