-1

我可以知道这个http连接有什么问题吗?运行此程序时出现“HTTP 问题”。

public void makeHttpPost(){
    try
     {
         //http post
        HttpPost httppost = new HttpPost("http://10.0.2.2/project/login.php");              
        HttpClient httpclient = new DefaultHttpClient();        
         httppost.setEntity(new UrlEncodedFormEntity(namevaluepairs));
         HttpResponse response = httpclient.execute(httppost);
         HttpEntity entity = response.getEntity();
         is = entity.getContent();
     }
     catch(Exception e)
     {
         Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
         Toast.makeText(getBaseContext(),"HTTP PROBLEM",Toast.LENGTH_LONG).show();
     }
}
4

1 回答 1

1

调用下面的类,你调用 makeHttpPost() 调用这个类如下:

    new LoadData().execute();


    class LoadData extends AsyncTask<Void, Void, Void> {

    @Override
    protected void onPreExecute() {
        // TODO Auto-generated method stub
        super.onPreExecute();

    }

    @Override
    protected Void doInBackground(Void... params) {
        // TODO Auto-generated method stub

         // ur http code
            makeHttpPost();
        return null;
    }

    @Override
    protected void onPostExecute(Void result) {
        // TODO Auto-generated method stub
        super.onPostExecute(result);



    }
}
于 2013-10-15T05:14:21.533 回答