webread
Read content from RESTful web service
Syntax
Description
appends query parameters todata
= webread(url
,QueryName1,QueryValue1,...,QueryNameN,QueryValueN
)url
, as specified by one or more pairs of name-value arguments. To put a query into the body of the message, usewebwrite
. The web service defines the query parameters.
adds other HTTP request options, specified by thedata
= webread(___,options
)weboptions
objectoptions
. You can use this syntax with any of the input arguments of the previous syntaxes.
To return data as a specific output type, specify theContentType
property ofoptions
.
To read content with a function, specify theContentReader
property ofoptions
as a handle to the function.webread
downloads data from a web service and reads the data with the specified function:
If you specify a handle to a function that returns multiple output arguments,
webread
returns all output arguments.If you specify a handle to a function that returns no output argument (such as Image Processing Toolbox™ function
@implay
for video files),webread
returns no output argument.
[
reads an image from the web service specified bydata
,colormap
,alpha
] = webread(___)url
and returns the image indata
. You can use the previous syntaxes to return the image only. Use this syntax to return the colormap and alpha channels associated with the image.
webread
returns an image when the HTTP response has aContent-Type
header field that specifies an image media type and ifimread
supports the image format. For supported image formats, seeSupported File Formats for Import and Export.
[
reads audio data from the web service specified bydata
,Fs
] = webread(___)url
and returns the audio data indata
. You can use the previous syntaxes to return the audio data only. Use this syntax to return the sample rate of the audio data in hertz.
webread
returns audio data when the HTTP response has aContent-Type
header field that specifies an audio media type and ifaudioread
supports the audio format. For supported audio formats, seeSupported File Formats for Import and Export.
Examples
Input Arguments
Output Arguments
More About
Tips
For functionality not supported by the RESTful web services functions, see theUse HTTP with MATLAB.
webread
supports HTTP GET and POST methods. Many web services provide both GET and POST methods to request data. To send an HTTP POST request, specify theRequestMethod
property ofoptions
as'post'
. However,webread
puts query options into theurl
, not in the body of the request message. To put a query into the body, usewebwrite
.For HTTP POST requests, the
webread
function supports only theapplication/x-www-form-urlencoded
media type. To send a POST request with content of any other internet media type, usewebwrite
.This function does not examine the document contents to determine how to process it. For example, HTML and XML documents often contain a
tag that specifies the document character encoding. If the encoding is different from the default
webread
encoding, then specify the correctCharacterEncoding
option inweboptions
.To specify proxy server settings, seeProxy Server Authentication.
Version History
Introduced in R2014b