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. class


HTTP request message


Use the RequestMessage class to format HTTP request messages to send to a server for processing. Use the send method to send the message, or the complete method to validate the message before sending. These methods fill in any necessary header fields and other message properties.


obj = creates a request message with default values. When you send or complete a message, the default Method property is RequestMethod.GET.


obj =,header,body) specifies one or more optional message properties. You can omit trailing arguments and use [] to specify any placeholders.

obj =,header,body) sets the RequestLine property to requestLine. Use this syntax if you need control over the contents of the request line. For example, to send a message explicitly to a proxy, set the RequestLine.RequestTarget property to the full URI. Otherwise, MATLAB chooses the proxy based on your proxy settings, and the send method sets the RequestTarget to the Path property of the URI.

obj =,header,provider) gets the message body data from a


expand all

Request line, specified as a object or a string or character vector that contains the method, target, and protocol version. This line is automatically created when you send a message, based on the method and URI you specify. If you set this property explicitly, then its contents are used as the request line. The value might be set to a RequestLine object or to a string which is parsed and converted to a RequestLine object.

Example: 'GET HTTP/1.1'



Request method, specified as a object, a string, a character vector, or empty ([]). To specify a method, set the RequestMessage.Method property or the RequestLine.Method property.


Example: 'get'



Message header, specified as a object or a vector of HeaderField objects. When you set the Header property, MATLAB® checks the fields of the header to ensure that they are appropriate for the message type. The RequestMessage send and complete methods fill in any required header fields for a properly formed request.

Message body, specified as a object,, or data acceptable to the MessageBody constructor. By default, Body is empty (set to []). A request message containing a Body property normally uses a method such as 'PUT' or 'POST', not the default value 'GET', but this convention is not enforced.

In a completed or received message, if the message has a ContentTypeField header field, then the MessageBody.ContentType property is set to that value. Otherwise, ContentType is unchanged or empty.

Whether message is complete, specified as true or false. A true value means that the message was completed.

Methods that validate messages (RequestMessage.send and RequestMessage.complete) set the Completed property to true after:

  • Determining that the message is valid.

  • Completing processing, such as adding required header fields and converting the data.

If the property is true, then these methods do not modify the message, and the send method sends the message without checking it for validity. Any change to this message after that changes the Completed property back to false.

To send arbitrary headers and data in a request message, set Completed to true to prevent the send method from modifying the message. You can still use the complete method to validate the message, but the send method sends it whether it is valid.

If a request message contains data (the Body.Data property is not empty), then Completed is set to true only if Body.Payload contains the raw data. In a response message, the payload is set only if you specify the HTTPOptions.SavePayload property.



Data Types: logical


completeValidate and complete HTTP request message without sending
sendSend HTTP request message and receive response




collapse all

Format an HTTP message requesting a server to add text to a website. This example only formats the message and does not send the data.

Add content to the message body.

data = 'Data to send';
body =;
Data to send

Create a Content-Type header field describing the data type of the body.

contentTypeField ='text/plain');

Create an Accept header field specifying the data types acceptable in the response message.

type1 ='text/*');
type2 ='application/json','q','.5');
acceptField =[type1 type2]);

Create a request header containing the two header fields.

header = [acceptField contentTypeField];

Specify that this message is a PUT request.

method =;

Create the request message and display the contents.

request =,header,body);
Accept: text/*, application/json; q=.5
Content-Type: text/plain

Data to send

Introduced in R2016b

Was this topic helpful?