O adrese HTTP GET isteği atacaksın alttaki gibi:
class RequestTask extends AsyncTask<String, String, String>{
@Override
protected String doInBackground(String... uri) {
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response;
String responseString = null;
try {
response = httpclient.execute(new HttpGet(uri[0]));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
responseString = out.toString();
out.close();
} else{
//Closes the connection.
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
} catch (ClientProtocolException e) {}
catch (IOException e) {}
return responseString;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
//TXT dosya içeriği result içinde
}
}Alttaki gibi de çalıştırırsın:
new RequestTask().execute("http://benim.com/deneme.txt");Kaynak:
http://stackoverflow.com/questions/3...t-with-android