java - Opening url.openstream throws invalid http response -


i trying read file temperature module, when call openstream() on url receive ioexeption message "invalid http response"

severe: null java.io.ioexception: invalid http response @ sun.net.www.protocol.http.httpurlconnection.getinputstream0(httpurlconnection.java:1555) @ sun.net.www.protocol.http.httpurlconnection.getinputstream(httpurlconnection.java:1441) @ java.net.url.openstream(url.java:1038) @ thermometerpoller.poller.poll(poller.java:38) 

i can telnet temperature module:

telnet 192.168.142.55 80 trying 192.168.142.55... connected 192.168.142.55. escape character '^]'. /state.xml http/1.1  <?xml version='1.0' encoding='utf-8'?> <datavalues> <units>f</units> <sensor1temp>74.0</sensor1temp> <sensor2temp>67.0</sensor2temp> <sensor3temp>xx.x</sensor3temp> <sensor4temp>xx.x</sensor4temp> <relay1state>0</relay1state> <relay2state>0</relay2state> </datavalues>  connection closed foreign host. 

it seems temperature module isn't sending headers reply. unfortunately , when @ httpurlconnection.java if there no response code throws ioexception.

my question is, there way file contents out caring response code either via library or method?

since server not http compliant, shouldn't use url or urlconnection. use plain socket instead:

document doc;  final socket connection = new socket("192.168.142.55", 80);  try (final outputstream out = connection.getoutputstream();      inputstream in = connection.getinputstream()) {      callable<void> requestsender = new callable<void>() {         @override         public void call()         throws ioexception {             string request = "get /state.xml http/1.1\n\n";             out.write(request.getbytes(standardcharsets.us_ascii));             return null;         }     };     executorservice background = executors.newsinglethreadexecutor();     future<?> request = background.submit(requestsender);      doc = documentbuilderfactory.newinstance().newdocumentbuilder().parse(in);      request.get();     background.shutdown(); } 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -