I am using the following code to get a page’s source which is a plain text (no html tags) from a webserver on LAN. But I am always getting empty string in return and If I open the same URI in browser I can see the text. Following is my code:
String url = "http://192.168.1.40/touchscreens/get.qsp?display=1";
HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet();
request.setHeader("Content-Type", "text/plain; charset=utf-8");
request.setURI(new URI(url));
HttpResponse response = client.execute(request);
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuffer sb = new StringBuffer("");
String line = "";
String NL = System.getProperty("line.separator");
while ((line = in.readLine()) != null) {
sb.append(line + NL);
}
String page = sb.toString();
Toast.makeText(getApplicationContext(), page, Toast.LENGTH_LONG).show();
and one more thing when I enter the same URL in android emulator browser I don’t see anything. Am i missing something?
I recommend you should debug your HTTP requests using fiddler (see http://www.fiddler2.com/fiddler2/). This should debug the internet requests from your browser and your app and show you if your requests are missing the necessary headers.