【问题标题】:I keep getting these kind of errors in terms of HttpUrlConnection and BackGroundTask in android我在android中的HttpUrlConnection和BackGroundTask方面不断收到这类错误
【发布时间】:2017-06-18 23:43:27
【问题描述】:

以下是logcat中的错误结果:

这是我的代码:

【问题讨论】:

标签: php android json parsing


【解决方案1】:

你加了吗

<uses-permission android:name="android.permission.INTERNET" />

进入 AndroidManifest.xml ? 您可以尝试使用 post 方法将代码发送到服务器。

@Override

protected Void doInBackground(Void... params) {


    try {


        HttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost("https://192.168.2.95/LAfinal/api/login_student.php");

        // ADD YOUR DATA
        List<NameValuePair> nameValuePairs = new ArrayList<>();
        nameValuePairs.add(new BasicNameValuePair("id", _activity.LOGINED_USER_ID));
        Log.v("HTTP", "Response__activity.LOGINED_USER_ID: " + String.valueOf(_activity.LOGINED_USER_ID));
        nameValuePairs.add(new BasicNameValuePair("token", _activity.fcmRegId));
        Log.v("HTTP", "Response___activity.fcmRegId: " + _activity.fcmRegId);
        nameValuePairs.add(new BasicNameValuePair("status", String.valueOf(_notificationStatus)));
        Log.v("HTTP", "Response_notificationStatus: " + String.valueOf(_notificationStatus));
        nameValuePairs.add(new BasicNameValuePair("type", "android"));
        httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

        // EXECUTE HTTP POST REQUEST
        HttpResponse response = httpClient.execute(httpPost);
        HttpEntity resEntity = response.getEntity();
        //resEntity.getContent().close();
        int status = response.getStatusLine().getStatusCode();
        if (status == 200) {
            if (_notificationStatus == 1) {
                WebViewActivity._needLogin = false;
            } else {
                WebViewActivity._needLogin = true;
            }
        }

        if (resEntity != null) {
            String responseStr = EntityUtils.toString(resEntity).trim();
            Log.v("HTTP", "Response: " + responseStr);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return null;
}`

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-12-07
    • 1970-01-01
    • 2019-06-25
    • 1970-01-01
    • 1970-01-01
    • 2020-04-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多