在Android服务上尝试HTTPresponse时出错

时间:2013-11-09 00:19:51

标签: android httpresponse

我有一个简单的类,它有一个调用httpResponse的方法,问题是,当我从服务中调用此方法时它会崩溃,有人可以帮我修复我的错误吗?

    public class A(){

public String detailhtml(String Url, String params)
            throws ClientProtocolException, IOException {
        HttpGet httpGet = new HttpGet(Url + params);
        HttpResponse httpResponse = new DefaultHttpClient().execute(httpGet);
        // validar la respuesta http es correcta
        if (httpResponse.getStatusLine().getStatusCode() == 200) {
            String HtmlString = EntityUtils.toString(httpResponse.getEntity());

            return HtmlString.trim();
        } else {
            return null;
        }
    }//  

}

这是我崩溃的服务:

public class serviceHTTP extends Service {
 public void onStart(Intent intent, int startId) {
   String Rhtml= A.detailhtml(url, parametros);
 }

}

0 个答案:

没有答案