简体   繁体   中英

Android studio - Failed to connect to LDAP server

I want use LDAP in android studio, I use UnboundID LDAP SDK for Java in the latest version.

I use the command:

LDAPConnection ldap = new LDAPConnection("xxx.xxx.xx.xx", 389,"uid=guest3,ou=Users,dc=gal,dc=local", guest3);

Connection details:

  • host: xxx.xxx.xx.xx
  • port: 389
  • dn: uid=guest3,ou=Users,dc=gal,dc=local
  • password: guest3

But When I try to connect to the LDAP server, I get the following error:

LDAPException(resultCode=82 (local error), errorMessage='An error occurred while encoding the LDAP message or sending it to server xx.xxx.xx.xx:389: NetworkOnMainThreadException(trace='onNetwork(StrictMode.java:1303) / socketWrite(SocketOutputStream.java:111) / write(SocketOutputStream.java:157) / flushBuffer(BufferedOutputStream.java:82) / flush(BufferedOutputStream.java:140) / sendMessage(LDAPConnectionInternals.java:580) / sendMessage(LDAPConnection.java:4375) / process(SimpleBindRequest.java:556) / bind(LDAPConnection.java:2270) / bind(LDAPConnection.java:2215) / onClick(LoginActivity.java:57) / performClick(View.java:5610) / run(View.java:22265) / handleCallback(Handler.java:751) / dispatchMessage(Handler.java:95) / loop(Looper.java:154) / main(ActivityThread.java:6077) / invoke(Method.java:native) / run(ZygoteInit.java:866) / main(ZygoteInit.java:756)', ldapSDKVersion=4.0.4, revision=27051)')

If anyone know how to remedy this issue, it would be greatly appreciated. Thanks in advance!

NetworkOnMainThreadException Maybe try not to do network on the main thread. see for reference

Getting the click event

  public void onClick(View v) {
  new Thread(new Runnable() {
    public void run() {
      final Bitmap b = loadImageFromNetwork();
      mImageView.post(new Runnable() {
        public void run() {
          mImageView.setImageBitmap(b);
        }
      });
    }
  }).start();
}

The goal of AsyncTask is to take care of thread management for you. Our previous example can easily be rewritten with AsyncTask:

public void onClick(View v) {
  new DownloadImageTask().execute("http://example.com/image.png");
}

private class DownloadImageTask extends AsyncTask {
     protected Bitmap doInBackground(String... urls) {
         return loadImageFromNetwork(urls[0]);
     }

     protected void onPostExecute(Bitmap result) {
         mImageView.setImageBitmap(result);
     }
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM