使用 CodeName One 登录到 NTLM 服务器
Log into a NTLM server with CodeName One
所以我是代号 1 的新手,
我正在尝试使用 HTLM 登录服务器,
我将如何实现这一目标?
我找不到任何有助于解决此问题的资源。
在此处找到https://docs.oracle.com/javase/8/docs/technotes/guides/net/http-auth.html
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
public class RunHttpSpnego {
static final String kuser = "username"; // your account name
static final String kpass = password; // retrieve password for your account
static class MyAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
// I haven't checked getRequestingScheme() here, since for NTLM
// and Negotiate, the usrname and password are all the same.
System.err.println("Feeding username and password for " + getRequestingScheme());
return (new PasswordAuthentication(kuser, kpass.toCharArray()));
}
}
public static void main(String[] args) throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL(args[0]);
InputStream ins = url.openConnection().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
String str;
while((str = reader.readLine()) != null)
System.out.println(str);
}
}
NTLM 需要 OS 的本机支持。你在那里所做的将在 JavaSE 上运行,其中模拟器是 运行 但不会在设备上运行。
要使其在设备上运行,您需要本机代码 描述了如何为 Android 完成此操作。要实现它,您需要创建一个本机界面并在本机界面中调用此代码:
jcifs.Config.registerSmbURLHandler();
从那时起,其余的应该从代号一开始工作。请注意,您还需要将 library that's required 放在 native/android 目录中。
栅栏的 iOS 侧应该与此 how to send NTLM request in iOS
一起使用
特别是这个块:
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: _host
port: 80
protocol: @"http"
realm: _host
authenticationMethod:NSURLAuthenticationMethodNTLM];
所以我是代号 1 的新手, 我正在尝试使用 HTLM 登录服务器, 我将如何实现这一目标?
我找不到任何有助于解决此问题的资源。
在此处找到https://docs.oracle.com/javase/8/docs/technotes/guides/net/http-auth.html
import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
public class RunHttpSpnego {
static final String kuser = "username"; // your account name
static final String kpass = password; // retrieve password for your account
static class MyAuthenticator extends Authenticator {
public PasswordAuthentication getPasswordAuthentication() {
// I haven't checked getRequestingScheme() here, since for NTLM
// and Negotiate, the usrname and password are all the same.
System.err.println("Feeding username and password for " + getRequestingScheme());
return (new PasswordAuthentication(kuser, kpass.toCharArray()));
}
}
public static void main(String[] args) throws Exception {
Authenticator.setDefault(new MyAuthenticator());
URL url = new URL(args[0]);
InputStream ins = url.openConnection().getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(ins));
String str;
while((str = reader.readLine()) != null)
System.out.println(str);
}
}
NTLM 需要 OS 的本机支持。你在那里所做的将在 JavaSE 上运行,其中模拟器是 运行 但不会在设备上运行。
要使其在设备上运行,您需要本机代码 描述了如何为 Android 完成此操作。要实现它,您需要创建一个本机界面并在本机界面中调用此代码:
jcifs.Config.registerSmbURLHandler();
从那时起,其余的应该从代号一开始工作。请注意,您还需要将 library that's required 放在 native/android 目录中。
栅栏的 iOS 侧应该与此 how to send NTLM request in iOS
一起使用特别是这个块:
NSURLProtectionSpace *protectionSpace = [[NSURLProtectionSpace alloc]
initWithHost: _host
port: 80
protocol: @"http"
realm: _host
authenticationMethod:NSURLAuthenticationMethodNTLM];