I keep getting these kind of errors in terms of HttpUrlConnection and BackGroundTask in android

Have you add

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

into AndroidManifest.xml ?
You can try code here send to server with method 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;
}`

Leave a Comment