Java tutorial
/* * * Copyright (C) Roberto Calvo Palomino * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see http://www.gnu.org/licenses/. * * Author : Roberto Calvo Palomino <rocapal at gmail dot com> * */ package es.rocapal.utils.Download; import java.io.IOException; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; import org.apache.http.HttpStatus; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.util.EntityUtils; import android.util.Log; public class HTTPActions { public String doGetPetition(String url) { try { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpGet httpGet = null; httpGet = new HttpGet(url); HttpResponse response = httpclient.execute(httpGet); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { HttpEntity entity = response.getEntity(); String str = EntityUtils.toString(entity); Log.d("doGetPetition", str); return str; } return String.valueOf(response.getStatusLine().getStatusCode()); } catch (IOException e) { Log.e("doGetPetition", e.getMessage()); return null; } } }