I want to be able to access custom URLs with apache httpclient. Something like this:
HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("media:///squishy.jpg");
int statusCode = client.executeMethod(method);
Can I somehow register a custom URL handler? Or should I just register one with Java, using
URL.setURLStreamHandlerFactory(...)
Regards.
We do it like this:
org.apache.commons.httpclient.protocol.Protocol.registerProtocol("ss-https",
new Protocol("ss-https",
(ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443));
I don't think there's a way to do this in commons httpclient. It doesn't make a whole lot of sense either, after all it is a HTTP client and "media:///squishy.jpg" is not HTTP, so all the code to implement the HTTP protocol probably couldn't be used anyways.
URL.setURLStreamHandlerFactory(...)
could be the way to go, but you'll probably have to do a lot of protocol coding by hand, depending on your "media"-protocol.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.