How can I debug 400-type error messages from "webread" and "webwrite" in MATLAB R2024b?
Show older comments
I am trying to send a request to a website with the "webwrite" command and capture the output. The website should receive the request and send back a payload of data, but I am getting a vague error that does not help me figure out why I can't access the site.
The error I am seeing is "The server returned the status 403 with message "Forbidden" in response to the request to URL". I can access the site perfectly fine through a browser and outside of MATLAB, so I don't know why I am getting this error when using "webread" in MATLAB.
Accepted Answer
More Answers (1)
Richard Zapor
on 7 Sep 2025
A slight variation when sending a JSON string to a site to get a response and catching the error if a 400 event happens
options=weboptions('MediaType', 'application/json');
try
response=webwrite(url,JSON_string,options)
catch
import matlab.net.http.*
body=JSON_string;
r=RequestMessage('POST',[],body);
resp=r.send(url);
show(resp)
resp.Body.Data
end
Categories
Find more on Call Web Services from MATLAB Using HTTP in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!