我正在使用Apache HttpClient 4,它能正常工作。唯一不正常的事情是自定义端口。似乎只有根目录被获取,端口被忽略。
HttpPost post = new HttpPost("http://myserver.com:50000");
HttpResponse response = httpClient.execute(post);
如果没有定义端口,http和https连接将正常工作。 方案注册表定义如下:
final SchemeRegistry sr = new SchemeRegistry();
final Scheme http = new Scheme("http", 80,
PlainSocketFactory.getSocketFactory());
sr.register(http);
final SSLContext sc = SSLContext.getInstance(SSLSocketFactory.TLS);
sc.init(null, TRUST_MANAGER, new SecureRandom());
SSLContext.setDefault(sc);
final SSLSocketFactory sf = new SSLSocketFactory(sc,
SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
final Scheme https = new Scheme("https", 443, sf);
sr.register(https);
我如何为请求定义自定义端口?
final Scheme http = new Scheme("http", 50000, PlainSocketFactory.getSocketFactory());
吗? - Angel O'Sphere