Validate and complete HTTP request message without sending
adds and validates message header fields and converts data like the
target] = complete(
RequestMessage.send method, but does not send the message.
complete assumes a default
HTTPOptions object to
determine how to complete and validate the request.
complete method to examine the contents
of a request message for debugging purposes.
To fill in and validate the
RequestLine properties, this method ignores the
Completed property in
method always returns a modified
request is not completed, then the method errors. You can
use this behavior to determine whether a manually completed request is valid.
Completed is not set, then this method always converts
request.Body and stores the
completedrequest.Body.Payload, overwriting any
previous contents of
Payload. This means that both
completedrequest.Body contain values. This is different
from the behavior of the
send which does not save the
is set. If the message contains a large amount of data, then memory usage and
conversion time might be a factor.
request.Body contains a
complete does not call the
provider to create data.
completedrequest.Body contains the
If you intend to send
completedrequest to avoid the cost of a
repeat validation, send it to
target instead of
uri, using the same
Time-dependent header fields such as
Date which are added by the
send method, are not updated when sent again using
completedrequest — Completed and validated request
Completed and validated request, returned as a
matlab.net.http.RequestMessage object. The
Completed property is true.
target — Completed URI
Completed URI, returned as a
Validate Request Message
Create a request message for a fictional website. Then, validate and complete the request without sending it.
request = matlab.net.http.RequestMessage(); url = 'myschool.edu/campus.jpg'; options = matlab.net.http.HTTPOptions('SavePayload',true); [request,url] = complete(request,url,options); show(request)
GET /campus.jpg HTTP/1.1 Host: myschool.edu User-Agent: MATLAB/18.104.22.1686741 (R2016b) Date: Wed, 13 Jul 2016 17:21:08 GMT Connection: close
relevant to your system.
Show the updated URL.
ans = http://myschool.edu/campus.jpg
A completed request does not add any authorization header fields that might be needed for authentication to a server or proxy, even if the
Authenticateproperty is set in
options. It might not be possible to determine what the server requires without sending the message. To see what was sent in an authentication exchange, examine the
historyarguments returned by the
To send the same request message repeatedly, send
completedrequest. Otherwise, if you send
request, then MATLAB repeatedly validates the message. Also be sure to specify
targetas the URI and the same
optionsinput argument. Time-dependent header fields such as Date, which the
sendmethod adds, are not updated when sending
To complete a message without converting the data, set the
truebefore calling the
Completedis true and
MessageBodyobject, then the
completemethod assumes that the current value of
request.Body.Payloadis the desired one, even if it is empty.
This behavior differs from the
request.Body.Payloadis empty, then
sendconverts and sends nonempty
Body.Datavalues, even if
Introduced in R2016b