0
I am creating an http server on Arduino, which given a request it responds to the following:
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println("Refresh: 5");
client.println();
client.println("<!DOCTYPE HTML>");
client.println("<html>");
timeNow = millis()/60000;
String times = String(timeNow, DEC);
String response = "{\n\"Response\": {\"workTime\":\"";
response += times;
response += "\"},\n";
response += "\"status\": \"200\"\n}";
client.println(response);
client.println("<br />");
client.println("</html>");
in the browser get this:
Chrome headers:
Request URL: http://1**.**.**.202:***0/resetRelogio
Request Method: GET
Status Code: 200 OK
Remote Address: 1**.**.**.202:***0
Referrer Policy: no-referrer-when-downgrade
Connection: close
Content-Type: text/html
Refresh: 5
Accept:
text/html,
application/xhtml+xml,
application/xml;q=0.9,
image/webp,
image/apng,*/*;q=0.8,
application/signed-exchange;v=b3
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,pt-BR;q=0.8,pt;q=0.7
Cache-Control: max-age=0
Connection: keep-alive
Cookie: qrClose=true; JSESSIONID=4db49dbd10380e82eb364e4fcd9636
Host: 1**.**.**.202:***0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (X11; Fedora; Linux x86_64) AppleWebKit/537.36
(KHTML, like Gecko) Chrome/73.0.3683.75 Safari/537.36
In my test with Xios I have this:
const axios = require('axios')
axios.get('http://172.40.24.202:4000/resetRelogio')
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log("error");
console.log(error);
})
as an answer we have:
I’ve searched a lot on google, so I understood the Rduino closes the connection unexpectedly, but I send a
client.println("Connection: close");
that the browser should understand the answer and close the connection. I needed Xios to return the body data.
And there is a
/n
after the\"200\"
that is wrong.– Woss
Response += ""status": "200"/n}"; here is part of my reply body, is a json the status code is in the beginning. correct me if I’m wrong
– Joannis
But this
/n
shouldn’t be\n
, which is a line break?– Woss
yes, it was a typo. Thank you!
– Joannis