How do I set a proxy server to use with the URLREAD and URLWRITE functions in MATLAB?

9 views (last 30 days)
My computer is located behind a firewall. In order to connect to the Internet, I need to specify a proxy server. However, I am unable to use URLREAD or URLWRITE to connect to external sites.

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 13 Dec 2021
Edited: MathWorks Support Team on 13 Dec 2021
In order to specify a proxy server for use in MATLAB, you will need to set two Java system properties: 'http.proxyHost' and 'http.proxyPort'. These properties correspond to the hostname of the proxy server, and the port that is used to connect to the proxy server, respectively.
If you are using MATLAB 7.0 (R14) or later versions, you can set these properties by going to "File -> Preferences -> Web". Then, check the "Use proxy to connect to the internet" checkbox and enter the values in the "Proxy server" and "Proxy port" editboxes.
If you are using a previous version of MATLAB, you will need to set these properties from the Command Window using the following commands:
java.lang.System.setProperty('http.proxyHost','myproxy.mycompany.com')
java.lang.System.setProperty('http.proxyPort','1234')
replacing 'myproxy' and '1234' with the appropriate values. You may want to add these commands to a startup.m file, so they are executed every time you start MATLAB. See the following for more information regarding startup.m:
Alternately, use the following lines of code in your file:
com.mathworks.mlwidgets.html.HTMLPrefs.setUseProxy(true)com.mathworks.mlwidgets.html.HTMLPrefs.setProxyHost('HostName')com.mathworks.mlwidgets.html.HTMLPrefs.setProxyPort('1234')
%% the proxy authentication is required
com.mathworks.mlwidgets.html.HTMLPrefs.setUseProxyAuthentication(true)com.mathworks.mlwidgets.html.HTMLPrefs.setProxyUsername('test')com.mathworks.mlwidgets.html.HTMLPrefs.setProxyPassword('test')
If you are compiling and deploying your MATLAB code to a target machine, in order to set the same settings for your compiled application on the target machine, add the following lines to your MATLAB code before you compile:
if isdeployed
com.mathworks.mlwidgets.html.HTMLPrefs.setUseProxy(true)
com.mathworks.mlwidgets.html.HTMLPrefs.setProxyHost('HostName')
com.mathworks.mlwidgets.html.HTMLPrefs.setProxyPort('Port')
end
where 'HostName' is the name of the Proxy Host and 'Port' is the port number on which the user needs to connect to the proxy server.

More Answers (0)

Categories

Find more on MATLAB Compiler in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!