Last active
June 29, 2023 17:19
-
-
Save scivision/360d7a8b95f5d5f1df79f78e0c9847ae to your computer and use it in GitHub Desktop.
Get and Set Matlab HTTP user agent
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function user_agent() | |
%% Get Matlab user agent | |
% Setting user agent for a client can help get around servers that ban non-allow-listed user agents. | |
w = weboptions; | |
disp("Matlab user agent: " + w.UserAgent) | |
url = "https://www.whatsmyua.info/api/v1/ua"; | |
fn = websave(tempname, url); | |
meta = jsondecode(fileread(fn)); | |
disp("Matlab user agent: " + meta{1}.ua.rawUa) | |
%% Set Matlab user agent | |
w.UserAgent = "Mozilla/5.0"; | |
fn = websave(tempname, url, w); | |
meta = jsondecode(fileread(fn)); | |
disp("Matlab user agent: " + meta{1}.ua.rawUa) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment