Error using webread and websave to retrieve JSON data from RESTful web service
이전 댓글 표시
version '9.7.0.1247435 (R2019b) Update 2'
I am attempting to read data returned from a web service using either webread or websave. The relevant MATLAB code is as follows:
service_url = "https://webservice.testserver.com/results?format=json";
opts = weboptions("HeaderFields", {'Authorization' api_token});
results_resp = webread(service_url, opts);
The error returned is:
Error using matlab.internal.webservices.HTTPConnector/copyContentToFile (line 412)
The server returned the status 400 with message "Bad Request" in response to the request to URL
Error in readContentFromWebService (line 62)
copyContentToFile(connection, filename);
Error in webread (line 125)
[varargout{1:nargout}] = readContentFromWebService(connection, options);
I have also tried websave, with the code above becoming:
service_url = "https://webservice.testserver.com/results?format=json";
opts = weboptions("HeaderFields", {'Authorization' api_token});
results_resp = websave("the_json_file.txt", service_url, opts);
The error returned is similar:
Error using matlab.internal.webservices.HTTPConnector/copyContentToFile (line 412)
The server returned the status 400 with message "Bad Request" in response to the request to URL
Error in websave (line 107)
copyContentToFile(connection, filename);
I note that the following command using curl on the Linux command line works fine.
curl -H "Authorization: api_token" -L "https://webservice.testserver.com?format=json"
답변 (1개)
Tim Kennedy
2020년 1월 2일
카테고리
도움말 센터 및 File Exchange에서 JSON Format에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!