Error using webwrite (line 136), Could not access server.
10 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
amador zuniga
il 20 Nov 2023
Commentato: amador zuniga
il 5 Dic 2023
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.
0 Commenti
Risposta accettata
Dheeraj
il 1 Dic 2023
Hi,
I understand that you are encountering an error when trying to contact a host using “webwrite”. This error might indicate issues with DNS resolution.
The error you're encountering is because MATLAB's “webwrite” function is using an outdated hostname when attempting to make the POST request to the new domain. When you provide the hostname as 'http://name0.name1.name2-name3.com/v1/measurements', MATLAB tries to resolve it using an internal DNS server that doesn't have the updated record for the new domain. This prevents MATLAB from establishing a connection to the server and result in the "Could not access server" error.
To resolve this issue, you can explicitly specify the IP address of the new domain in the URL string. This will bypass MATLAB's internal DNS resolution and ensure that the request is sent to the correct server.
If the steps did not seem to work and result in the same error, you should validate the SSL certificate of the instance.
You could refer to the below MATLAB documentation on “webwrite” better understanding.
Hope this Helps!
Più risposte (0)
Vedere anche
Categorie
Scopri di più su JSON Format in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!