Error using webwrite (line 136), Could not access server.
Afficher commentaires plus anciens
I'm running matlab R2019b in an EC2 AWS instance.
I am using webwrite to make a post request through an API.
My code has been working long time with an old URL, but it fails with the new one. (We are migrating to a new domain)
'http://ip-number1-number2-number3-number4-number5.YYYY.compute.internal/v1/measurements' % it works
'http://name0.name1.name2-name3.com/v1/measurements' % it works
'http://name0.name1.name2/v1/measurements'; % it doesn't work
My code (quick test) is:
URL = 'http://ip-number1-number2-number3-number4-number5.YYYY.compute.internal/v1/measurements';
API_KEY = '0L03GF498GT3486GMN34T7G5N2DX2C380U4TV329M'; % not real api_key
DATA = ['"TIMESTAMP","VALUE"' char(10) ...
'"2023/11/15 00:30:00","6577.40"' char(10) ...
'"2023/11/15 01:00:00","6482.62"'];
VALUES = struct("apiKey", API_KEY, ...
"values", struct("dataVariable", DATA));
VALUES.values.dataElement = {VALUES.values.dataElement};
VALUES.values = {VALUES.values};
VALUES = jsonencode(VALUES);
% Options
OPTIONS = weboptions('Timeout', 60, 'HeaderFields',{'Content-Type' 'application/json'});
% Send POST request
[response] = webwrite(URL, VALUES, OPTIONS)
when the code works, it returns:
response =
struct with fields:
codError: 0
requestId: '823459781112'
valuesCount: [1×1 struct]
when it doesn't:
Error using webwrite (line 136)
Could not access server. http://name0.name1.name2-name3.com/v1/measurements.
It doesn't return 401, 404 error or gives any extra information.
I have no idea how to solve it.
I discarted AWS configuration, because when I run the query using a web browser it works and returns a json.
Maybe matlab manage internaly a white-list URL, SSL certificates or something like that.
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Startup and Shutdown dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!