1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
| public class Test extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
String result = "rien";
URL url = null;
// Log.d(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " location = " + location);
try {
url = new URL("http://testandroid.hebergratuit.com/index.php?ville=\"rabat\"");
// Log.d(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " url = " + url);
} catch (MalformedURLException e) {
// Log.e(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " " + e.getMessage());
Log.i("error", e.getMessage());
}
if (url != null) {
try {
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(urlConn.getInputStream()));
String inputLine;
inputLine = in.readLine();
result += "\n" + inputLine;
in.close();
urlConn.disconnect();
} catch (IOException e) {
// Log.e(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " " + e.getMessage());
Log.i("error2", e.getMessage());
}
} else {
// Log.e(Constants.LOGTAG, " " + SimpleGet.CLASSTAG + " url NULL");
}
Log.i("result", result);
}
} |
Partager