Não estou conseguindo fazer o download no site da sun do Java Commerce™ Toolkit.
Então Preciso obter uma URL passando por um proxy que utiliza senha sem utilizar a classe javax.commerce.util.BASE64Encoder.
Tentei trocar a javax.commerce.util.BASE64Encoder por sun.misc.BASE64Encoder:
import java.io.*;
import java.net.*;
import sun.misc.BASE64Encoder;
public class PassProxy {
public PassProxy(String proxyhost, String proxyport, String proxylogin, String proxypass, String url) {
/* Set the proxy server host and port */
System.setProperty("http.proxyHost", proxyhost);
System.setProperty("http.proxyPort", proxyport);
/* Set up and encode the proxy credentials */
String s = proxylogin + ":" + proxypass;
String se = new BASE64Encoder().encodeBuffer(s.getBytes());
try {
/* Create a HttpURLConnection Object and set the properties */
URL u = new URL(url);
HttpURLConnection uc = (HttpURLConnection) u.openConnection();
uc.setRequestProperty("Proxy-Authorization", "Basic " + se);
uc.connect();
/* Print the content of the url to the console. */
showContent(uc);
} catch (IOException e) {
e.printStackTrace();
}
}
private void showContent(HttpURLConnection uc) throws IOException {
InputStream i = uc.getInputStream();
char c;
InputStreamReader isr = new InputStreamReader(i);
BufferedReader br = new BufferedReader(isr);
String line;
while ((line = br.readLine()) != null) {
System.out.println(line);
}
}
public static void main(String[] args) {
String proxyhost = "xxxxxxx";
String proxyport = "80";
String proxylogin = "xxxx";
String proxypass = "xxxx";
String url = "http://www.guj.com.br";
new PassProxy(proxyhost, proxyport, proxylogin, proxypass, url);
}
}
Mas ta dando o seguinte erro:
java.lang.IllegalArgumentException: Illegal character(s) in message header value: Basic U291emFNUjpub21pbmltbw==
at sun.net.www.protocol.http.HttpURLConnection.checkMessageHeader(HttpURLConnection.java:171)
at sun.net.www.protocol.http.HttpURLConnection.setRequestProperty(HttpURLConnection.java:1200)
at PassProxy.<init>(PassProxy.java:26)
at PassProxy.main(PassProxy.java:54)