我一直在使用 httpClient 尝试将连接字符串写入 https-base API,并且用户名/密码验证有点棘手。
使用 Appache commons base64 编码器我被迫将一个字节数组传递给构造函数,我的身份验证应该是 email@companyName:password 但是 base 64 转换器不支持 @ 符号(因为它不是 0-9 az 或 az或 /+),但是这显然需要在我可以进行身份验证之前解决......帮助?
代码(在请求之前):
import org.apache.commons.codec.binary.Base64;
....
String encoding = Base64.encodeBase64String("username@company.com:password");
HttpPost httppost = new HttpPost("https://webapi.com/api/protectedarea");
httppost.setHeader("Authorization", "Basic " + encoding);
完整的错误代码:
javax.net.ssl.SSLPeerUnverifiedException: peer not authenticated
at sun.security.ssl.SSLSessionImpl.getPeerCertificates(SSLSessionImpl.java:397)
at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:128)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:397)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:148)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:150)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:121)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:575)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:425)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:820)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:754)
at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:732)