试图建立NTLM连接,但是我的jython不够熟练,无法翻译Authenticator部分代码。我需要什么信息来完成此任务?如果在jython中甚至可以做到这一点。
from java.net import Authenticator
from java.net import PasswordAuthentication
from java.net import URL
from java.net import HttpURLConnection
from java.lang import StringBuilder
from java.io import InputStream, BufferedReader
from java.io import InputStreamReader
url = ""
domain = ""
user = ""
pswd = ""
'''Authenticator.setDefault( new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(domain + "\\" + user, pswd.toCharArray());
}
});
'''
urlReq = URL(url)
con = urlReq.openConnection()
con.setRequestMethod("GET")
res = StringBuilder()
s = con.getInputStream()
isr = InputStreamReader(s)
br = BufferedReader(isr)
ins = br.readLine()
while ins is not None:
res.append(ins)
ins = br.readLine()
br.close()
print("stuff:"+res.toString())
答案 0 :(得分:0)
在Authenticator中查看JavaDocs可能会有所帮助。这应该使您接近要寻找的东西:
from java.net import Authenticator
from java.net import PasswordAuthentication
from java.net import URL
from java.net import HttpURLConnection
from java.lang import StringBuilder
from java.io import InputStream, BufferedReader
from java.io import InputStreamReader
url = ""
domain = ""
user = ""
pswd = ""
'''Authenticator.setDefault( new Authenticator() {
@Override
public PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(domain + "\\" + user, pswd.toCharArray());
}
});
'''
auth = Authenticator()
auth.PasswordAuthentication(domain + "\\" + user, pswd.toCharArray())
setDefault(auth)
urlReq = URL(url)
con = urlReq.openConnection()
con.setRequestMethod("GET")
res = StringBuilder()
s = con.getInputStream()
isr = InputStreamReader(s)
br = BufferedReader(isr)
ins = br.readLine()
while ins is not None:
res.append(ins)
ins = br.readLine()
br.close()
print("stuff:"+res.toString())