Reputation: 185
DefaultHttpClient defaultHttpClient=new DefaultHttpClient();
HttpGet httpGet=new HttpGet(url);
HttpResponse httpResponse=defaultHttpClient.execute(httpGet);
InputStream inputStream=httpResponse.getEntity().getContent();
BufferedReader bufferedReader=new BufferedReader(new InputStreamReader(inputStream));
I am trying to communicate with a server with this code in AsyncTask.
The server is arduino(microcontroller) controlled server. The server is working fine. I tried it with browser with the url.
The problem is that the I made the server to respond only with a string of "OK" as acknowledgement without a http header like below or any other thing to reduce the overload.
HTTP/1.1 200 OK
Content-Type: text/html; charset=UTF-8
Content-Length: 128
Connection: close
When I run this code I get error that the response is not valid http response.
Is there is way to get the acknowledgement string of "OK" only.
Upvotes: 0
Views: 53
Reputation: 26584
If you really really really don't want the overhead of http, then you can simply open your own socket, write your request, and read the response. To me it sounds like more work than just adding a few headers in your response from arduino.
The java tutorial shows how to read/write with a socket. https://docs.oracle.com/javase/tutorial/networking/sockets/readingWriting.html
Upvotes: 1