请问java访问用户名和密码的http协议该如何写?
需要访问具有用户名和密码输入的http网址,请问java代码该如何访问呢?
以下代码无法成功,不知为什么,请帮忙解决。
URL myURL = new URL(url);
URLConnection conn = myURL.openConnection();
//用户名密码部分
String username = "XXXX";
String password = "XXXXX";
String input = username + ":" + password;
String encoding = new String(Base64.encode(new String(XXXX+":"+XXXXX).getBytes()));
conn.setRequestProperty( "Proxy-Authorization","Basic"+encoding);
//
conn.connect();
------解决方案--------------------
URL myURL = new URL(url + "?username=" + username + "&password=" + password);
------解决方案--------------------
httpclient 4.1.3实现的,lz看下
// 用户认证
String userName = "XXXX";
String password = "XXXX";
CredentialsProvider credsProvider = new BasicCredentialsProvider();
UsernamePasswordCredentials usernamePassword = new UsernamePasswordCredentials(
userName, password);
credsProvider.setCredentials(AuthScope.ANY, usernamePassword);
httpclient.setCredentialsProvider(credsProvider);
HttpPost httpPost = new HttpPost(url);
HttpResponse response = httpclient.execute(httpPost);
------解决方案--------------------Java code
conn.setRequestProperty("Authorization", "Basic " + encoding);
------解决方案--------------------
basic后面有一个空格
------解决方案--------------------
你是在android访问还是普通java总访问https?
有数字证书吗?
------解决方案--------------------
------解决方案--------------------
------解决方案--------------------