Process or reprocess response payload Content-Type
returns a copy of the message with
msg = complete(
matlab.net.http.io.ContentConsumer. The consumer might store its result in
msg.Body.Data or process it in some other manner.
complete method when:
Body.Datawas unset or not set properly because the server inserted the wrong Content-Type in the message or the Content-Type was missing.
You set the ConvertResponse
falseto prevent conversion of the data when it was originally received.
You specified the wrong
consumerwhen sending the message.
If there was an exception processing the received message, or if you set the
HTTPOptions.SavePayload property when you sent the request,
Body.Payload in this response message contains the original
payload (if any). In this case, modify the header of this message to add or correct
the Content-Type field. Then call the
complete method to process
the response as if the server had inserted that Content-Type field originally. The
result is new contents in
Data processed by the specified
Body.Payload is set, then this method ignores the current value of
Body.Data and reprocesses that payload based on
Content-Type. This case occurs for a conversion error or if you specified
SavePayload. But if conversion of the incoming data
succeeded originally, but was incorrect,
Body.Data is set and
Body.Payload might be empty. In this case, change the
ContentTypeField in the received message to the desired type and then call this
complete attempts to convert the data back to a payload
based on the
Body.ContentType property used to convert it
originally. Then it is reconverted using the new Content-Type header in the response
Data is not empty, then the returned
Body.Payload is set.
If you specified
SavePayload when sending
complete uses the original payload that
was preserved in
Body.Payload instead, with no
loss of information.
ResponseMessage.Completed property is set,
complete does nothing. In a message that contains a
Body, this property is normally set only if
Body.Payload has been set.
text/plain Content-Type Field
Assume that the server returned a response
containing a JSON string but specified a Content-Type field of
application/json. In this case,
msg.Body.Data contains an ASCII string
(since the default charset for
To process this data and obtain a JSON structure:
response = response.changeFields('Content-Type','application/json'); response = response.complete(); data = response.Body.Data;
The call to
The method then reconverts
processing it as a JSON string and storing the result in
This conversion does not retain any non-ASCII characters that were
garbled when converting the original payload using
preserves the original ASCII data.
Introduced in R2016b