Class: matlab.net.http.RequestMessage
Package: matlab.net.http
Send HTTP request message and receive response
[
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.Completed
property to
true
before sending. If you used the
complete
method to complete the request, then you
should specify the same value of uri
and
options
that you provided to
complete
, or there might be unpredictable results. Even
if Completed
is set, unspecified fields in the
RequestLine
will be filled in with default
values.
To allow the send
method to check and alter the header,
but suppress adding a particular header field that send
or
a ContentProvider
might add, add that field to
request.Header
with an empty value
([]
). For example, send
automatically adds a User-Agent header field. If you do not want this
behavior, then add HeaderField('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 send
method 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
a ContentProvider
might add. However, for some header field
types, send
might 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 a ContentProvider
adds, add a field of
type matlab.http.field.GenericField
to the header with the
desired name and value. Neither send
nor a
ContentProvider
will add any header fields with names
equal to any GenericField
headers and will not check their
correctness.
To send raw binary data without conversion, you can insert a
uint8
vector into either
Body.Data
or Body.Payload
. The
only difference is that data in Body.Data
is subject to
conversion based on the Content-Type field in the message, while
Body.Payload
is not. send
always
tries to convert nonempty Body.Data
if
Body.Payload
is empty, even if
Completed
is already set. See
MessageBody.Data
for conversion rules.
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 in options
.
Status
property of response
— Web service responds
and returns an HTTP error status. send
returns normally,
setting the Status
property to the error returned
from the server.
complete
| HTTPException
| HTTPOptions
| LogRecord
| matlab.net.http.field.GenericField
| matlab.net.http.io.ContentConsumer
| matlab.net.http.io.ContentProvider
| matlab.net.URI