Webread - How to get Web Response Code ?

Hi,
I am using webread function to read web contents to my matlab program. I also would like to receive web response code, for example, 401, if web connection is wrong.
Webread function does not return this web response code. Does anyone know how to do this?

回答 (1 件)

Rahul
Rahul 2025 年 6 月 25 日

0 投票

While 'webread' does not expose the response metadata like status code or headers, you can consider using the 'matlab.net.http' package which would give control over http request and response.
Here is an example:
import matlab.net.*
import matlab.net.http.*
% Define the URI
uri = URI('https://httpbin.org/basic-auth/user/passwd');
% Create a GET request message
request = RequestMessage;
response = request.send(uri);
% Display the status code
disp("Status code: " + response.StatusCode)
The following MathWorks documentations can be referred to know more:
Thanks.

カテゴリ

ヘルプ センター および File ExchangeCall Web Services from MATLAB Using HTTP についてさらに検索

製品

タグ

質問済み:

2018 年 12 月 6 日

回答済み:

2025 年 6 月 25 日

Community Treasure Hunt

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

Start Hunting!

Translated by