2
目前我使用的Apache CommonsVFS抓取其他網站的圖像和它工作得很好。阿帕奇CommonsVFS連接到https服務器
CommonsVFS的網站表示它支持HTTPS協議,但我發現我無法訪問那些以https://開始使用CommonVFS的URL,而我通常可以通過我的Firefox訪問browse it。
例如,下面的代碼將產生一個異常說無法連接到HTTP服務器..
scala> import org.apache.commons.vfs.VFS
import org.apache.commons.vfs.VFS
scala> val fsManager = VFS.getManager();
fsManager: org.apache.commons.vfs.FileSystemManager = [email protected]
scala> val file1 = fsManager.resolveFile ("http://bone.twbbs.org.tw/Images/desk.jpg")
file1: org.apache.commons.vfs.FileObject = http://bone.twbbs.org.tw/Images/desk.jpg
scala> val file2 = fsManager.resolveFile ("https://na.archives.gov.tw/archives/chinese/98/search/popup.jsp?res=/export/home/xdcm/do/ScaleDoFiles/jpg/00/00/01/21/07/A313480000K=0089=577=1=1=003=0002-i.jpg")
org.apache.commons.vfs.FileSystemException: Could not connect to HTTP server on "na.archives.gov.tw".
at org.apache.commons.vfs.provider.http.HttpClientFactory.createConnection(HttpClientFactory.java:105)
at org.apache.commons.vfs.provider.http.HttpFileProvider.doCreateFileSystem(HttpFileProvider.java:81)
at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:81)
at org.apache.commons.vfs.provider.AbstractOriginatingFileProvider.findFile(AbstractOriginatingFileProvider.java:62)
at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:641)
at org.apache.commons.vfs.impl.DefaultFileSystemManager.resolveFile(DefaultFileSystemManager.java:602)
at org.apache.commons.vfs.impl.DefaultFileS...
我也嘗試添加HTTPS提供商文件管理器,但仍然有沒有運氣,它說URL方案「HTTPS」已被註冊。
scala> fsManager.asInstanceOf[org.apache.commons.vfs.impl.StandardFileSystemManager].addProvider("https", new org.apache.commons.vfs.provider.https.HttpsFileProvider)
org.apache.commons.vfs.FileSystemException: Multiple providers registered for URL scheme "https".
at org.apache.commons.vfs.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:174)
at org.apache.commons.vfs.impl.DefaultFileSystemManager.addProvider(DefaultFileSystemManager.java:152)
at .<init>(<console>:8)
at .<clinit>(<console>)
at RequestResult$.<init>(<console>:9)
at RequestResult$.<clinit>(<console>)
at RequestResult$scala_repl_result(<console>)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at scala.tools.nsc.Interpr...
那麼,我該如何使用commonVFS訪問https服務器呢?