How do I stop webread from converting "%2B" into "+"?

Unforunately, every time it webread runs it converts the all of the "%2B" into "+" and then returns an error. How do I get it to use the exact URL as entered???
It keeps returning this error:
Error using matlab.internal.webservices.HTTPConnector/copyContentToFile (line 389)
The server returned the status 403 with message "Forbidden" in response to the request to URL
https://s3.amazonaws.com/appforest_uf/f1620499445726x864228122125595900/JBL%20VRX932LAP%20PSHF+3dB%20-%202m%20-%207150%20142.csv.
Error in readContentFromWebService (line 62)
copyContentToFile(connection, filename);
Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
Here's my code:
TF = webread('https://s3.amazonaws.com/appforest_uf/f1620499445726x864228122125595900/JBL%20VRX932LAP%20PSHF%2B3dB%20-%202m%20-%207150%20142.csv')

7 Comments

It looks like webread includes a subcommand to reencode the URL. Maybe there is some option to stop it from doing that?
Colin tipped me off to a workaround with urlread. urlread is not recommend, says the documentation so I have submitted a bug report. If anyone else runs into this issue, here's my code.
try
TFurl = 'https://s3.amazonaws.com/appforest_uf/f1620499445726x864228122125595900/JBL%20VRX932LAP%20PSHF%2B3dB%20-%202m%20-%207150%20142.csv';
TF = webread(TFurl);
TF.Properties.VariableNames = {'Frequency_Hz','Magnitude_dB','Phase_deg','Coherence'};
catch
TFstr = urlread(TFurl);
TFarray = splitlines(TFstr);
TFarray(1:2) = [];
TFcell = cell(height(TFarray),4);
for i=1:1:height(TFarray)
TFcell(i,:) = strsplit(TFarray{i},',');
end
TFdouble = str2double(D);
TF = array2table(E,'VariableNames',{'Frequency_Hz','Magnitude_dB','Phase_deg','Coherence'});
end
Mathworks has denied my bug report because I don't have an active subscription. If anyone else has had this problem, please submit a bug report.
You could also try double-encoding the URL. (replace the % with its symbol)
Ohhh, tell me more about that.
  1. Is there an MATLAB command to encode the URL?
  2. Your thinking is that if the all of the "%2B" are changed to "+" ahead of time that then webread will change them back to "%2B"?
There isn't any command that I'm aware of. The idea is to replace every character with a value above 255 (or with a special meaning) by its hexadecimal version. So '+' becomes '%2B'. Since webread parses your URL for these changes, you can double-encode them: use '%252B' instead.
The idea is that webread parses the '%25' to a percent symbol and leaves the rest as is.
I have not tested this idea.
Thanks Rik. I tried this. Unfortunately, it produces the same error.
oldURL = 'https://s3.amazonaws.com/appforest_uf/f1620499445726x864228122125595900/JBL%20VRX932LAP%20PSHF%2B3dB%20-%202m%20-%207150%20142.csv';
newURL = strrep(url,'%2B','%252B');
TF = webread(newURL);

Sign in to comment.

Answers (0)

Categories

Products

Release

R2021a

Asked:

on 10 Oct 2021

Commented:

on 25 Oct 2021

Community Treasure Hunt

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

Start Hunting!