Documentation

websave

将内容从RESTFUL Web服务保存到文件

Syntax

OUTFILENAME = WESTAVE(文件名,URL)
OUTFILENAME = WESTAVE(文件名,URL,queryname1,queryvalue1,...,querynamen,queryvaluen)
OUTFILENAME = WESTAVE(___,options)

描述

example

OUTFILENAME = WESTAVE(filename,URL)干腊肠es content from the web service specified byURL并写信给filename。这websave功能将完整的文件名路径返回outfilename

这web service provides aRESTful APIthat returns data formatted as an internet media type such as JSON, XML, image, or text.

example

OUTFILENAME = WESTAVE(filename,URL,queryname1,queryvalue1,...,querynamen,queryvaluen)appends query parameters toURL,如一对或多对名称值参数所指定的。Web服务定义查询参数。

example

OUTFILENAME = WESTAVE(___,选项)adds other HTTP request options, specified by theweboptionsobject选项。You can use this syntax with any of the input arguments of the previous syntaxes.

websavesupports HTTP GET and POST methods. To send an HTTP POST request, specify theRequestMethodproperty of选项as'邮政'。Many web services provide both GET and POST methods to request data.

例子

全部收缩

Save an image of Jupiter from the Hubble Heritage website.

URL ='http://heritage.stsci.edu/2007/14/images/p0714aa.jpg';文件名='jupiter_aurora.jpg';OUTFILENAME = WESTAVE(文件名,URL)
OUTFILENAME = C:\ Libraries \ Documents \ Jupiter_aurora.jpg

websave干腊肠es the image as a JPEG file, as specified by the Hubble web service, even when you givefilename不同的扩展。(木星图像由NASA,ESA和哈勃遗产团队(STSCI/AURA)提供。请参阅Hubble Heritage Information Centerfor terms of use.)

搜索文件交换以在过去7天内上传的文件包含该单词金宝app®和display the results of the search.

URL ='//www.tatmou.com/matlabcentral/fileexchange/';文件名='simulink_search.html';OUTFILENAME = WESTAVE(文件名,URL,'term','simulink','duration',7)
outfilename = C:\Libraries\Documents\simulink_search.html

在Web浏览器中显示HTML文件。

Web(OutfileName)

将黑子数据从国家地球物理数据中心(NGDC)保存到ASCII文件。用一个weboptionsobject to set the timeout value toinf因此连接不会超时。

api ='http://www.ngdc.noaa.gov/stp/space-weather/';URL =[api'Solar-Data/Solar-Indices/Sunspot-numbers/'。。。'american/lists/list_aavso-arssn_yearly.txt']; filename ='sunspots_annual.txt';选项= WebOptions('Timeout',Inf); outfilename = websave(filename,url,options)
OUTFILENAME = C:\ liberaries \ Documents \ Sunspots_annual.txt

一个ggregated data and web service courtesy of the NGDC. Sunspot data courtesy of the American Association of Variable Star Observers (AAVSO), originally published in AAVSO Sunspot Counts: 1943-2013, AAVSO Solar Section (R. Howe, Chair). (SeeNGDC隐私政策,免责声明和版权供NGDC使用条款,以及AAVSO太阳能部分for AAVSO terms of use.)

将HTTP POST请求发送到搜索文件交换以获取过去7天内上传的文件,该文件包含该单词金宝app。Save the results of the search to an HTML file.

URL ='//www.tatmou.com/matlabcentral/fileexchange/';文件名='simulink_search.html';选项= WebOptions('RequestMethod','邮政');OUTFILENAME = WESTAVE(文件名,URL,'term','simulink','duration',7,选项);

许多Web服务提供了一种邮政方法,用于要求数据以外的数据。

保存蓝色大理石:2004年12月的下一代图像从NASA地球观测(NEO)网络映射服务中。

用一个指定请求图像的日期约会时间目的。Specify the格式property ofDso that the format matches the format required by the web service.

URL ='http://neowms.sci.gsfc.nasa.gov/wms/wms';D = datetime(2004,12,01,'Format','yyyy-mm-dd');文件名='bluemarble.jpg';OUTFILENAME = WESTAVE(文件名,URL,'Time',D,。。。'服务','WMS','Layers','Bluemarbleng-TB',“ CRS”,'CRS:84',。。。'Format',“图像/jpeg','高度',256,'宽度',512,。。。'bbox','-180.0,-90.0,180.0,90.0','Version','1.3.0','Request','GetMap')
outfilename = C:\Libraries\Documents\BlueMarble.jpg

websave转换约会时间对象使它们可以成为Web服务查询参数的值。示例中的所有名称值对提供了NEO Web映射服务指定的查询参数。

Blue Marble: Next Generation + Topography and Bathymetry image courtesy of NASA's Earth Observatory. Access to imagery and services provided by the NEO Web Mapping Service (WMS). (SeeNASA地球观测供信用和使用条款。看WMS 1.3.0 Capabilitiesfor WMS query parameters.)

输入参数

全部收缩

Name of file to save content to, specified as a character array.websave干腊肠es the content as is.websaveignores选项。ContentType选项。ContentReader,即使设置了这些属性。

例子:websave('matlabcentral.html','//www.tatmou.com/matlabcentral')读取网页并将其HTML保存到文件matlabcentral.html

URL到Web服务,指定为字符阵列。Web服务实现了一个安息的接口。看RESTful APIfor more information.

Web service query parameters, specified as one or more pairs of name-value arguments. AQueryName参数必须指定查询参数的名称。一个QueryValueargument must be a character array or a numeric, logical, or约会时间指定查询参数的值的值。数字,逻辑和约会时间values can be in arrays. The web service defines name-value pairs that it accepts as part of a request.

什么时候you specifyQueryValue作为一个约会时间object, you must specify its格式属性符合Web服务所需的格式。如果是格式属性包括时区或偏移,约会时间object is not zoned, thenwebsave指定'Local'作为时区。

什么时候QueryValuecontains multiple values in an array, you might need to specify thearrayformat财产的weboptionsobject to form-encode the array as specified by the web service.

例子:WebSave('Webread_search.html','http://www.tatmou.com/matlabcentral/fileexchange/'term'term金宝app'simulink')检索上传到包含单词的文件交换的文件列表金宝app和干腊肠es the search results to an HTML file.

其他HTTP请求选项,指定为weboptions目的。对于所有请求选项weboptions属性,请参阅weboptions

More About

全部收缩

RESTful API

休息方法代表性国家转移,一种用于Web服务的常见建筑风格。RESTFUL API或接口提供标准的HTTP方法,例如GET,PUT,POST或DELETE。

提示

  • For functionality not supported by the RESTful web services functions, see theHTTP Interface

  • For HTTP POST requests, thewebsavefunction supports only the应用/X-WWW-Form-urlenCodedmedia type. To send a POST request with content of any other internet media type, useWebwrite

在R2014b中引入

这个话题有帮助吗?