hoe om url hanteerder vir apache Commons httpclient registreer
-
02-07-2019 - |
Vra
Ek wil in staat wees om toegang te verkry tot persoonlike URL's met apache httpclient. Iets soos hierdie:
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("media:///squishy.jpg");
int statusCode = client.executeMethod(method);
Kan ek een of ander manier te registreer 'n persoonlike URL hanteerder? Of moet ek registreer net een met Java, met behulp van
URL.setURLStreamHandlerFactory(...)
Groete.
Oplossing
Ek dink nie daar is 'n manier om dit te doen in commons httpclient. Dit maak nie 'n hele klomp van die sin óf maak, na alles is dit is 'n HTTP kliënt en "media: ///squishy.jpg" is nie HTTP, so al die kode aan die HTTP-protokol waarskynlik kon nie anyways gebruik te implementeer .
URL.setURLStreamHandlerFactory(...)
kan die pad om te gaan, maar jy sal waarskynlik 'n baie protokol kodering doen met die hand, na gelang van jou "media" -protocol.
Ander wenke
Ons doen dit soos volg:
org.apache.commons.httpclient.protocol.Protocol.registerProtocol("ss-https",
new Protocol("ss-https",
(ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443));
Gelisensieer onder: CC-BY-SA met toeskrywing
Nie verbonde aan StackOverflow