当前位置: 代码迷 >> Android >> Android的post请求有关问题,
  详细解决方案

Android的post请求有关问题,

热度:75   发布时间:2016-05-01 21:04:15.0
Android的post请求问题,急!!!!!!在线等
Java code
public String clickInfo_Java() {        String result = "";        try {            final String SERVER_URL = "http://10.0.2.2:8080/tm/AndroidAction_Android_FindByCarNumber"; // 定义需要获取的内容来源地址            HttpPost request = new HttpPost(SERVER_URL); // 根据内容来源地址创建一个Http请求            request.setHeader("Content-Type", "application/x-www-form-urlencoded");               List<NameValuePair> params = new ArrayList<NameValuePair>();            params.add(new BasicNameValuePair("cardnumber", "123124212536")); // 添加必须的参数            params.add(new BasicNameValuePair("x", Math.random() + "")); // 添加必须的参数            request.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); // 设置参数的编码            // HttpResponse httpResponse = new            // DefaultHttpClient().execute(request); // 发送请求并获取反馈            HttpClient client = new DefaultHttpClient();            [color=#FF0000]HttpResponse httpResponse = client.execute(request);[/color]            // 解析返回的内容            if (httpResponse.getStatusLine().getStatusCode() != 404) {                result = EntityUtils.toString(httpResponse.getEntity());                System.out.println(result);            }        } catch (Exception e) {            Toast.makeText(this, e.getMessage().toString(), Toast.LENGTH_LONG)                    .show();            e.printStackTrace();        }        return result;    }



每次 运行到 HttpResponse httpResponse = client.execute(request); 程序就跳到了 catch 然后 窗口出现 Permission denied(没有权限)。  

各位大神, 在线等, 急 !!!!!!!

------解决方案--------------------
AndroidManifest.xml中,添加网络访问权限:

<uses-permission android:name="android.permission.INTERNET" />
  相关解决方案