Weboptions: Timeout don't work

21 vues (au cours des 30 derniers jours)
YW
YW le 10 Oct 2016
Commenté : Isabel She le 16 Juil 2019
I am using the Example 1 from webread command help.
url = 'http://www.mathworks.com/matlabcentral/fileexchange'
searchTerm = 'sensor-data-acquisition'
html = webread(url,'term',searchTerm)
the webread always gave me error " timed out after 5 seconds. Set options.Timeout to a higher value." So I use the weboptions to specify the Timeout to inf, but webread don't seems to know.
options =
weboptions with properties:
CharacterEncoding: 'auto'
UserAgent: 'MATLAB 9.0.0.341360 (R2016a)'
Timeout: Inf
Username: ''
Password: ''
KeyName: ''
KeyValue: ''
ContentType: 'auto'
ContentReader: []
MediaType: 'application/x-www-form-urlencoded'
RequestMethod: 'auto'
ArrayFormat: 'csv'
html = webread(url,'term',searchTerm)
Error using webread (line 119) The connection to URL 'http://www.mathworks.com/matlabcentral/fileexchange?term=sensor-data-acquisition' timed out after 5 seconds. Set options.Timeout to a higher value.
  1 commentaire
Isabel She
Isabel She le 16 Juil 2019
After set options.Timeout = Inf, you just need to add options in the webread syntax, like this:
html = webread(url,'term',searchTerm,options)

Connectez-vous pour commenter.

Réponses (1)

Ankita Nargundkar
Ankita Nargundkar le 20 Oct 2016
Modifié(e) : Ankita Nargundkar le 20 Oct 2016
I see that your Timeout property in weboptions is set is Inf. By default it is 5. You are probably seeing the error because of this. You can reset the Timeout property in the following way from the MATLAB command window
>> options = weboptions
>> options.Timeout = 5
Now execute these lines below in MATLAB command window. You should be able to read data from the url.
>>url = 'http://www.mathworks.com/matlabcentral/fileexchange'
>>searchTerm = 'sensor-data-acquisition'
>>html = webread(url,'term',searchTerm)
I was able to successfully fetch the html data from the url in R2016a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by