Is there a built-in way to build a GET url in Matlab from a set of parameters?
Show older comments
0 down vote favorite
I'm trying to get data using an API that takes GET requests. The data are returned in XML format, so I'm hoping to use the xmlread function, which can take a URL as input. However, because the data comes from an API, I need to build the URL with the GET request's arguments and use that as the input for xmlread.
I don't want to use the urlread and urlwrite functions for these reasons:
1. If I use urlread, I get the data as a string, which can't be passed into xmlread.
2. If I use urlwrite, I have to write the data to a file and read it in from there, using xmlread, which is horribly inefficient when my functions make hundreds of API calls.
Is there a built-in Matlab function that allows me to pass in a URL and a cell array (or some other data type) of (argument_name, value) pairs and build a get URL from that? I'm assuming that if a canned method exists in basic Matlab, it will be more efficient than me writing my own that will be rife with string concatenation.
Accepted Answer
More Answers (1)
Yes, there is!
To create a URI query string form structure variable (or some other types):
% Define your query Data as a structure variable
sVar.Param1 = 'Value1';
sVar.Param2 = 'Value2';
EncodedURL = char(matlab.net.QueryParameter(sVar))
Categories
Find more on String 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!