weboptions — Create options for HTTP requests.
weboptions creates a host options structure for webread, websave, and webwrite.
Syntax
options = weboptions()
options = weboptions(optionsStruct)
options = weboptions(name, value, ...)
options = weboptions(optionsStruct, name, value, ...)Inputs
optionsStruct- Type
Any- Required
- Yes
- Description
- Existing options struct to copy and override (RunMat extension).
name- Type
StringScalar- Required
- Variadic
- Description
- Case-insensitive option field name.
value- Type
Any- Required
- Variadic
- Description
- Option field value.
Returns
options- Type
Any- Description
- Host HTTP options struct for webread, webwrite, and websave.
Errors
RunMat:weboptions:InvalidArgument- When
- Argument shape/type does not match supported weboptions forms.
- Message
weboptions: invalid argument
RunMat:weboptions:InvalidOptionName- When
- Name-value option key is missing or not text scalar.
- Message
weboptions: invalid option name
RunMat:weboptions:MissingOptionValue- When
- A name-value key is not followed by a value.
- Message
weboptions: missing option value
Forms and fields
weboptions() returns defaults; case-insensitive name-value pairs override them. In RunMat mode, an existing options struct may be copied and overridden. The input struct is not mutated.
The implemented fields are ContentType, Timeout, HeaderFields, UserAgent, Username, Password, KeyName, KeyValue, RequestMethod, MediaType, and the RunMat-only QueryParameters. Unknown names raise an error. CharacterEncoding, ContentReader, ArrayFormat, and CertificateFilename are not accepted by the current constructor or consumed by these HTTP operations.
The default timeout is 5 seconds. Timeout accepts a positive numeric scalar up to 2147.483647 seconds or Inf; accepted native integer values are converted to bounded timeout seconds. KeyValue accepts a text, numeric, or logical scalar and retains exact native integer storage. When paired with nonempty KeyName, webread and webwrite emit one HTTP header with exact integer decimal text.
ContentType accepts auto, json, text, or binary (with documented text/binary aliases). RequestMethod accepts auto, get, post, put, patch, or delete; the consuming operation decides whether a method is supported. HeaderFields accepts a struct or two-column cell array.
Empty username and password leave basic authentication disabled. A nonempty password without a username is rejected. HeaderFields and QueryParameters can be cleared with an empty struct or an empty two-column cell array.
Execution and compatibility
Options construction performs no network request. webread, webwrite, or websave later use the active host HTTP service to make a request; a stored option value does not own a session or grant transport capability.
Options are host metadata. Automatically resident values gather through their owning provider after pure option admission. Explicit gpuArray input requires the named RunMat extension before provider access. The resulting structure is host-resident and terminates fusion.
Copying an input struct and using QueryParameters are separate RunMat extensions. Both are rejected in MATLAB-compatible mode; ordinary name-value construction remains available.
This page's portable examples check the constructed fields without contacting a live endpoint. The webread and webwrite pages contain executable loopback examples that exercise these options against deterministic HTTP fixtures.
Examples
Set a request timeout
opts = weboptions('Timeout', 10);Expected output:
opts.Timeout = 10Store basic authentication credentials
opts = weboptions('Username', 'ada', 'Password', 'lovelace');Configure JSON request and response
opts = weboptions('ContentType', 'json', 'MediaType', 'application/json');Apply custom headers from a structure
headers = struct('Accept', 'application/json');
opts = weboptions('HeaderFields', headers);Copy options and override with query parameters
base = weboptions('ContentType', 'json');
opts = weboptions(base, 'Timeout', 15, 'QueryParameters', struct('verbose', true));Using weboptions with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how weboptions changes the result.
Run a small weboptions example, explain the result, then change one input and compare the output.
FAQ
Which option names are supported in RunMat?⌄
The constructor accepts ContentType, Timeout, HeaderFields, UserAgent, Username, Password, KeyName, KeyValue, RequestMethod, MediaType, and the RunMat-only QueryParameters. Unknown fields, including CharacterEncoding, ContentReader, ArrayFormat, and CertificateFilename, are rejected.
What does RequestMethod='auto' mean?⌄
webread treats auto as GET and webwrite treats it as POST. The consuming operation validates any explicit method it supports.
How are empty usernames or passwords handled?⌄
Empty values leave authentication disabled. A nonempty password without a username raises an error.
Can I pass query parameters through the options struct?⌄
Yes in RunMat mode: use a struct or two-column cell array for QueryParameters. MATLAB-compatible mode rejects this named extension.
Do I need to manage GPU residency for options?⌄
Automatically resident values gather through their owning provider. Explicit gpuArray values require RunMat mode; the returned struct is host-resident.
Does weboptions mutate the input struct?⌄
No. The RunMat copy-and-override form leaves the input struct unchanged.
How can I clear headers or query parameters?⌄
Use an empty struct or empty two-column cell array for the corresponding field.
Related Io functions
Repl Fs
addpath · cd · copyfile · delete · dir · exist · fileattrib · fileparts · filesep · fullfile · genpath · getenv · getpref · isenv · isfile · isfolder · ispref · ls · matlabroot · memmapfile · memmapfile.subsasgn · memmapfile.subsref · mkdir · movefile · open · opentoline · path · pathsep · pcode · pwd · readstruct · rehash · restoredefaultpath · rmdir · rmpath · run · savepath · setenv · setpref · system · tempdir · tempname · uigetdir · uigetfile · uiputfile · unsetenv · userpath · what · winqueryreg · xmlread · xmlwrite
Tabular
arrayDatastore · csvread · csvwrite · detectImportOptions · dlmread · dlmwrite · fileDatastore · getvaropts · parquetDatastore · parquetinfo · parquetread · readcell · readmatrix · readtable · readtimetable · setvaropts · setvartype · spreadsheetImportOptions · writecell · writematrix · writetable · writetimetable · xlsread · xlswrite
Data
commit · data.copy · data.create · data.delete · data.exists · data.export · data.import · data.inspect · data.list · data.move · data.open · DataArray.chunk_shape · DataArray.codec · DataArray.dtype · DataArray.fill · DataArray.name · DataArray.rank · DataArray.read · DataArray.resize · DataArray.shape · DataArray.write · Dataset.array · Dataset.arrays · Dataset.attrs · Dataset.begin · Dataset.get_attr · Dataset.has_array · Dataset.id · Dataset.path · Dataset.refresh · Dataset.set_attr · Dataset.set_attrs · Dataset.snapshot · Dataset.version · DataTransaction.abort · DataTransaction.commit · DataTransaction.create_array · DataTransaction.delete_array · DataTransaction.fill · DataTransaction.id · DataTransaction.resize · DataTransaction.set_attr · DataTransaction.set_attrs · DataTransaction.status · DataTransaction.write
Filetext
fclose · feof · fgetl · fgets · fileread · filewrite · fopen · fprintf · fread · frewind · fwrite · readlines · writelines
Import
Json
Source you can read
Every RunMat function's source is public. Read exactly how weboptions is executed, line by line, in Rust.
- View the source for weboptions in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is a runtime that executes MATLAB-syntax code fast on any GPU. The runtime is free for individuals, including freelancers; students and faculty at an academic institution, for teaching or research there; contributors to an open-source project, for work on that project; organizations with 250 or fewer people and US$10M or less in annual revenue; and anyone, for non-production use. See runmat.com/license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.