Android studio - 无法连接到 LDAP 服务器
Android studio - Failed to connect to LDAP server
我想在 android studio 中使用 LDAP,我在最新版本的 Java 中使用 UnboundID LDAP SDK。
我使用命令:
LDAPConnection ldap = new LDAPConnection("xxx.xxx.xx.xx", 389,"uid=guest3,ou=Users,dc=gal,dc=local", guest3);
连接详细信息:
- 主持人:xxx.xxx.xx.xx
- 端口:389
- dn: uid=guest3,ou=用户,dc=gal,dc=local
- 密码:guest3
但是当我尝试连接到 LDAP 服务器时,出现以下错误:
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)')
如果有人知道如何解决这个问题,将不胜感激。提前致谢!
NetworkOnMainThreadException
也许尽量不要在主线程上做网络。
查看 reference
获取点击事件
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();
}
AsyncTask 的目标是为您管理线程。我们前面的例子可以很容易地用 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);
}
}
我想在 android studio 中使用 LDAP,我在最新版本的 Java 中使用 UnboundID LDAP SDK。
我使用命令:
LDAPConnection ldap = new LDAPConnection("xxx.xxx.xx.xx", 389,"uid=guest3,ou=Users,dc=gal,dc=local", guest3);
连接详细信息:
- 主持人:xxx.xxx.xx.xx
- 端口:389
- dn: uid=guest3,ou=用户,dc=gal,dc=local
- 密码:guest3
但是当我尝试连接到 LDAP 服务器时,出现以下错误:
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)')
如果有人知道如何解决这个问题,将不胜感激。提前致谢!
NetworkOnMainThreadException 也许尽量不要在主线程上做网络。 查看 reference
获取点击事件
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();
}
AsyncTask 的目标是为您管理线程。我们前面的例子可以很容易地用 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);
}
}