Home Ask Login Register

Developers Planet

Your answer is one click away!

user5899421 February 2016

please help me i can not solve the code with HttpUrlConnection and all new for api 23

i am trying to make a login check from sever i have found this code from internet but now HttpClient and some other are deprecated for api 23 and higher. but i am unable to modify this with HttpUrlConnection,libray and all updates. so please need help badly.

main Activity:

package com.example.login;

import java.util.ArrayList;

import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

public class LoginLayout extends Activity {
    EditText un,pw;
    TextView error;
    Button ok;
    /** Called when the activity is first created. */
    public void onCreate(Bundle savedInstanceState) {

        ok.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                // TODO Auto-generated method stub

                ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
                postParameters.add(new BasicNameValuePair("username", un.getText().toString()));
                postParameters.add(new BasicNameValuePair("password", pw.getText().toString()));

                String response = null;
                try {
                    response = CustomHttpClient.executeHttpPost("<target page url>", postParameters);
                    String res=response.toString();
                    res= res.replaceAll("\\s+","");
                        error.setText("Correct Username or Password");


JustinMorris February 2016

While it has been deprecated you can still use it by adding this to your Gradle file:

android {
  compileSdkVersion 23
  buildToolsVersion "23.0.2"
  useLibrary 'org.apache.http.legacy'


Post Status

Asked in February 2016
Viewed 1,263 times
Voted 14
Answered 1 times


Leave an answer

Quote of the day: live life