Safari says “can't open page” but JSON return is normal [on hold]
Safari says “can't open page” but JSON return is normal [on hold]
My homebrew Wi-Fi temperature sensor works when connected to one of my access points, but with another one I get "Safari can't open the page because the server unexpectedly dropped the connection." Yet looking at the device log (in Arduino) it appears to respond correctly with a very short JSON record:
new client
Request: GET /temperature/F HTTP/1.1
Response: {"TempF":65.30}
Client disconnected
Also, accessing the device with curl http://xx.yy.zz.ww/temperature/F
produces the desired JSON response.
curl http://xx.yy.zz.ww/temperature/F
I don't know where to start looking for the problem (tried it with Chrome and got the same result).
I have Safari's "Develop" menu enabled. I've been through all the router settings and don't see anything that could cause this.
I'm using the Arduino ESP8266 library.
This question appears to be off-topic. The users who voted to close gave this specific reason:
And, the
request
are needed to build a HTTP request header, I guess the response
needs too.– Geno Chen
Jun 30 at 5:46
request
response
1 Answer
1
I don't have an Arduino board, and not used that library, however I think this can solve your issue.
As for my search of the Arduino ESP8266 library, it is just an TCP and UDP library, not an HTTP library. So you have to implement all the HTTP headers by yourself, which can also be indicated by Request
field in your question. Then I think if filling the Response
with a valid HTTP response format may solve this issue, for example
Request
Response
Response: HTTP/1.1 200 OKrnContent-Length: 15rnrn{"TempF":65.30}
Once I implemented both the Content-Type and Content-Length headers, it now works with all browsers. Unlike Safari, Firefox has a very nice feature that, for a JSON response, lets you see the decoded data, the raw data (optionally prettyprinted), or the headers. Nice!
– Robert Lewis
2 days ago
Is this response don't have any valid HTTP Headers? I don't know whether this library contains the part of automatically fill in the necessary HTTP Headers like "HTTP/1.1 200 OK" (the HTTP status code), but for my other project, sometimes this reason sucks.
– Geno Chen
Jun 30 at 5:43