How do I look at the payload of a webwrite response when the response is a 400 or other error?
Show older comments
How do I look at the payload of a "webwrite" response when the response is a 400 or other error? It throws a MATLAB error, but doesn't display any of the error messages the server sent back as payload.
My code looks something like this:
json_request = struct('a', nan);
json_response = webwrite('http://localhost:8000/reports/', json_request, ...
weboptions('MediaType', 'application/json', 'RequestMethod', 'post'))
Accepted Answer
More Answers (1)
Richard Zapor
on 6 Sep 2025
A slight variation on the Accepted answer is for when Posting a JSON string.
import matlab.net.http.*
body = MessageBody(jsonencode(data)); % or body=data_string of JSON
r = RequestMessage('POST', [], body);
resp = r.send(url);
show(resp)
resp.Body.Data %To see the error message content
Categories
Find more on JSON Format 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!