Why is http request blocked even though I have empty ProxyURI and no Web Settings proxy specified?

4 visualizzazioni (ultimi 30 giorni)
I am running MATLAB2024a on RedHat Enterprise Linux 8
in the matlab.net.http.HTTPOptions class documentation (https://www.mathworks.com/help/matlab/ref/matlab.net.http.httpoptions-class.html), it states in the UseProxy field:
All requests go directly to the destination URI without a proxy when any of the following is true.
  • UseProxy is false.
  • UseProxy is true but ProxyURI is empty and there is no proxy set in settings.
In the Preferences page, I have "Use a proxy server to connect to the internet" unchecked:
When I send an http request that ovverrides the UseProxy option to 'false', the request succeeds:
options = matlab.net.http.HTTPOptions( ...
'UseProxy',false)
options =
HTTPOptions with properties:
MaxRedirects: 20
ConnectTimeout: 10
UseProxy: 0
ProxyURI: []
Authenticate: 1
Credentials: [1×1 matlab.net.http.Credentials]
UseProgressMonitor: 0
SavePayload: 0
ConvertResponse: 1
DecodeResponse: 1
ProgressMonitorFcn: []
CertificateFilename: "default"
VerifyServerName: 1
DataTimeout: Inf
ResponseTimeout: Inf
KeepAliveTimeout: Inf
[response, ~, ~] = send(request, uri, options)
response =
ResponseMessage with properties:
StatusLine: 'HTTP/1.1 200 OK'
StatusCode: OK
Header: [1×3 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
However, when I send an http request using default options, I am faced with a bad gateway (uri and request ommitted intentionally, but they are the same in both examples):
options = matlab.net.http.HTTPOptions
options =
HTTPOptions with properties:
MaxRedirects: 20
ConnectTimeout: 10
UseProxy: 1
ProxyURI: []
Authenticate: 1
Credentials: [1×1 matlab.net.http.Credentials]
UseProgressMonitor: 0
SavePayload: 0
ConvertResponse: 1
DecodeResponse: 1
ProgressMonitorFcn: []
CertificateFilename: "default"
VerifyServerName: 1
DataTimeout: Inf
ResponseTimeout: Inf
KeepAliveTimeout: Inf
[response, ~, ~] = send(request, uri, options)
response =
ResponseMessage with properties:
StatusLine: 'HTTP/1.1 502 notresolvable'
StatusCode: BadGateway
Header: [1×5 matlab.net.http.HeaderField]
Body: [1×1 matlab.net.http.MessageBody]
Completed: 0
I believe I have exercised both cases called out in the documentation that would result in all requests going directly to the destination URI without a proxy, but the second example seems to violate the second case. What might be affecting my request?

Risposte (1)

Aditya
Aditya il 17 Lug 2025
Hi Daniel ,
It appears that the issue arises because, even though you have unchecked "Use a proxy server to connect to the internet" in MATLAB's Preferences, the default behavior of HTTPOptions with UseProxy=true and ProxyURI=[] causes MATLAB to check for system proxy environment variables (such as http_proxy or https_proxy) if no proxy is set in the preferences. If any of these environment variables are set, MATLAB will attempt to use them as a proxy. If the proxy specified by these variables is unreachable or misconfigured, you will receive a 502 Bad Gateway error. When you explicitly set UseProxy=false, MATLAB bypasses all proxy settings, which is why your request succeeds in that case. To resolve this, you should check and clear any proxy environment variables in your system before launching MATLAB, or clear them within your MATLAB session before making HTTP requests. This will ensure that requests with default options are sent directly, as intended.
% Check for proxy environment variables in MATLAB
getenv('http_proxy')
getenv('https_proxy')
getenv('HTTP_PROXY')
getenv('HTTPS_PROXY')
% Clear proxy environment variables in MATLAB
setenv('http_proxy','')
setenv('https_proxy','')
setenv('HTTP_PROXY','')
setenv('HTTPS_PROXY','')
After clearing these variables, try sending your HTTP request again with the default options. This should allow the request to go directly to the destination URI without attempting to use a proxy.

Tag

Prodotti


Release

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by