-
Notifications
You must be signed in to change notification settings - Fork 51
/
urlreadwrite.m
58 lines (50 loc) · 1.5 KB
/
urlreadwrite.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
function [urlConnection,errorid,errormsg] = urlreadwrite(fcn,urlChar)
%URLREADWRITE A helper function for URLREAD and URLWRITE.
% Matthew J. Simoneau, June 2005
% Copyright 1984-2007 The MathWorks, Inc.
% $Revision: 1.1.6.3.6.1 $ $Date: 2009/01/30 22:37:42 $
% Default output arguments.
urlConnection = [];
errorid = '';
errormsg = '';
% Determine the protocol (before the ":").
protocol = urlChar(1:min(find(urlChar==':'))-1);
% Try to use the native handler, not the ice.* classes.
switch protocol
case 'http'
try
handler = sun.net.www.protocol.http.Handler;
catch exception %#ok
handler = [];
end
case 'https'
try
handler = sun.net.www.protocol.https.Handler;
catch exception %#ok
handler = [];
end
otherwise
handler = [];
end
% Create the URL object.
try
if isempty(handler)
url = java.net.URL(urlChar);
else
url = java.net.URL([],urlChar,handler);
end
catch exception %#ok
errorid = ['MATLAB:' fcn ':InvalidUrl'];
errormsg = 'Either this URL could not be parsed or the protocol is not supported.';
return
end
% Get the proxy information using MathWorks facilities for unified proxy
% prefence settings.
mwtcp = com.mathworks.net.transport.MWTransportClientPropertiesFactory.create();
proxy = mwtcp.getProxy();
% Open a connection to the URL.
if isempty(proxy)
urlConnection = url.openConnection;
else
urlConnection = url.openConnection(proxy);
end