如何为Apache Commons httpclient注册URL处理程序 [英] how to register url handler for apache commons httpclient
问题描述
我希望能够使用apache httpclient访问自定义URL.像这样:
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);
我可以以某种方式注册自定义URL处理程序吗?还是我应该使用
Can I somehow register a custom URL handler? Or should I just register one with Java, using
URL.setURLStreamHandlerFactory(...)
致谢.
推荐答案
我认为在Commons httpclient中没有办法做到这一点.这也不是很有意义,毕竟它是一个HTTP客户端,而"media:///squishy.jpg"不是HTTP,因此实现HTTP协议的所有代码可能仍然无法使用
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.
这篇关于如何为Apache Commons httpclient注册URL处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!