send
Class: matlab.net.http.RequestMessage
Namespace: matlab.net.http
Send HTTP request message and receive response
Syntax
Description
[
sends the response,completedrequest,history] = send(request,uri)request message to the web service specified by
uri and returns the response, if any.
If no request.Method property is specified, then the
send method sets the property to
'GET'.
By default, send verifies the semantic correctness of the headers
and other parts of the message and completes the uri. The
method also fills in any required header fields for a properly formed request. If
request.Body is a MessageBody whose
Payload property is not already set, then
send calls appropriate conversion functions to convert any
request.Body.Data to a vector of bytes representing an HTTP
payload to be sent, as described for MessageBody.Data.
Normally, a 'GET' request does not contain data, but the method
sends the Body regardless of the
RequestMethod. If the server returns data in its response
and no consumer is specified, then send
converts that data to MATLAB® data and saves it in
response.Body.Data. See MessageBody.Data
for more information on data conversion.
If request.Body is a ContentProvider, then
MATLAB calls the provider to get the data to be sent.
If the header already contains a field that the method normally adds, then
send verifies that the field has the expected value. You can
override the default behavior as follows.
To send a message as is without any checking or alteration of the header, set the
request.Completedproperty totruebefore sending. If you used thecompletemethod to complete the request, then you should specify the same value ofuriandoptionsthat you provided tocomplete, or there might be unpredictable results. Even ifCompletedis set, unspecified fields in theRequestLinewill be filled in with default values.To allow the
sendmethod to check and alter the header, but suppress adding a particular header field thatsendor aContentProvidermight add, add that field torequest.Headerwith an empty value ([]). For example,sendautomatically adds a User-Agent header field. If you do not want this behavior, then addHeaderField('User-Agent')to the header. Header fields with empty values are not included in the message. The Host and Connection fields cannot be suppressed.To override the value that the
sendmethod adds for a given header field, add your own instance of that field before sending or completing the message. However, this will not override a header field that aContentProvidermight add. However, for some header field types,sendmight still reject the message if the value is not valid. To prevent any checking of the value of a given field, or to override a field that aContentProvideradds, add a field of typematlab.http.field.GenericFieldto the header with the desired name and value. Neithersendnor aContentProviderwill add any header fields with names equal to anyGenericFieldheaders and will not check their correctness.To send raw binary data without conversion, you can insert a
uint8vector into eitherBody.DataorBody.Payload. The only difference is that data inBody.Datais subject to conversion based on the Content-Type field in the message, whileBody.Payloadis not.sendalways tries to convert nonemptyBody.DataifBody.Payloadis empty, even ifCompletedis already set. SeeMessageBody.Datafor conversion rules.
Input Arguments
Output Arguments
Examples
Error Handling
Always check the response Status property
to determine whether the request was accepted. Error conditions are:
MException— Message is not well formed and cannot be completed.HTTPException— Message is completed, but the web service is unreachable or does not respond within the timeout period specified inoptions.Statusproperty ofresponse— Web service responds and returns an HTTP error status.sendreturns normally, setting theStatusproperty to the error returned from the server.
Version History
Introduced in R2016b