Skip to content

Instantly share code, notes, and snippets.

@scivision
Last active June 29, 2023 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save scivision/360d7a8b95f5d5f1df79f78e0c9847ae to your computer and use it in GitHub Desktop.
Save scivision/360d7a8b95f5d5f1df79f78e0c9847ae to your computer and use it in GitHub Desktop.
Get and Set Matlab HTTP user agent
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