Process or reprocess response payload Content-Type


msg = complete(msg) converts the msg.Body.Payload property to msg.Body.Data using the current value of the Content-Type header field in msg.


msg = complete(msg,consumer) returns a copy of the message with msg.Body.Payload processed by a The consumer might store its result in msg.Body.Data or process it in some other manner.

Use the complete method when:

  • Body.Data was 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 HTTPOptions.ConvertResponse property to false to prevent conversion of the data when it was originally received.

  • You specified the wrong consumer when 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, the 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 Body.Data and/or Data processed by the specified consumer.

If 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 method. 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 message. If Data is not empty, then the returned Body.Payload is set.

If you specified SavePayload when sending the message, complete uses the original payload that was preserved in Body.Payload instead, with no loss of information.

If the ResponseMessage.Completed property is set, complete does nothing. In a message that contains a Body, this property is normally set only if msg.Body.Payload has been set.

Input Arguments

expand all

Response message, specified as a object.

Output Arguments

expand all

Completed response message, returned as a object.


expand all

Assume that the server returned a response containing a JSON string but specified a Content-Type field of text/plain instead of application/json. In this case, Body.Payload is empty and msg.Body.Data contains an ASCII string (since the default charset for text/plain is us-ascii). 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 complete converts Body.Data to Body.Payload using us-ascii encoding. The method then reconverts Body.Payload to utf-8 before processing it as a JSON string and storing the result in Body.Data. This conversion does not retain any non-ASCII characters that were garbled when converting the original payload using text/plain but preserves the original ASCII data.

Introduced in R2016b