Android httpclient.execute(httpPost)错误

Android httpclient.execute(httpPost)错误,android,http-post,httpclient,Android,Http Post,Httpclient,在我的android应用程序中,我试图向远程服务器发送一个json对象,当我运行它时,我在httpclient.execute(httpPost)中得到一个错误 这是我代码的一部分 public static String GET(String url , JSONObject js){ try { HttpPost httpPost = new HttpPost(url); httpPost.addHeader("Authori

在我的android应用程序中,我试图向远程服务器发送一个json对象,当我运行它时,我在httpclient.execute(httpPost)中得到一个错误 这是我代码的一部分

public static String GET(String url , JSONObject js){ 

    try {
         HttpPost httpPost = new HttpPost(url);         

        httpPost.addHeader("Authorization", "Basic **********");
        httpPost.setEntity(new StringEntity(js.toString()));

        HttpClient httpclient = new DefaultHttpClient();            
        httpclient.execute(httpPost);
    } catch (Exception e) {
         Log.i("Console", "Error");
    }

请提供帮助。

我想您的问题是,您试图从主线程运行网络请求

我不鼓励您使用ApacheHTTP客户端

它不再被用于棉花糖,参见


也许试试。它为您提供了异步运行请求的可能性。

什么类型的错误?发布堆栈跟踪。。。可能在
catch
条款中添加
e.printStackTrace()
,我打赌错误类似于“NetworkOnMainThreadException”: