So here is the problem I’m having currently…I have a ASPX script that runs on a server (let’s say http://www.myserver.com/script.aspx)…when I open up this page via my web browser I get a plain text page with some data formated like this (just one line):
Data1|Data2|Data3|...
Now I need to fetch this data in my Android app which I did like this:
URL url = new URL("http://www.myserver.com/script.aspx");
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader((InputStream) urlConnection.getInputStream()));
String data = in.readLine();
System.out.println(data); // Just to print the result in LogCat for debug
urlConnection.disconnect();
The problem is that the resulting string only contains the letter ‘@’. No sign of my data. I have tried using other web page adresses (like google.com) to test if it’s a problem in my code…but it works…I allways get the first line of the page (usually the first html tag, since it’s a HTML web page).
I am guessing now that this is some kind of problem with the way I’m calling my ASPX script…how can I call it via Java so I get the same result as the browser (eg. the one line with my data)
Figured it out…I needed to set the user agent to a browser. So doing
did the trick. The only thing I am wondering now is what user-agent would be ideal to say “I am a browser”…this seems kinda long?