我想获取这个脏网址:http://relevancy.bger.ch/php/clir/http/index.php?highlight_docid=atf%3A%2F%2F115-IV-187%3Ade&lang=de&type=show_document
过了一段时间,我终于找到了这个解决方案。
val link = "http://relevancy.bger.ch/php/clir/http/index.php?highlight_docid=" +
java.net.URLEncoder.encode("atf://115-IV-187:de", "UTF-8") + "&lang=" +
java.net.URLEncoder.encode("de", "UTF-8") + "&type=" +
java.net.URLEncoder.encode("show_document", "UTF-8")
当我打印它时,我可以从终端点击它,然后在浏览器中打开页面。但是我在下面的代码中得到MalformedInputException
。
println(scala.io.Source.fromURL(link).mkString)
更新
例外说:
java.nio.charset.MalformedInputException: Input length = 1
at java.nio.charset.CoderResult.throwException(CoderResult.java:281)
at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:339)
at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178)
at java.io.InputStreamReader.read(InputStreamReader.java:184)
at java.io.BufferedReader.read1(BufferedReader.java:210)
at java.io.BufferedReader.read(BufferedReader.java:286)
at java.io.Reader.read(Reader.java:140)
at scala.io.BufferedSource.mkString(BufferedSource.scala:94)
at services.Downloader$.getAtf(Downloader.scala:47)
at controllers.JudgmentController.$anonfun$bot$1(JudgmentController.scala:71)
at scala.Function1.$anonfun$andThen$1(Function1.scala:52)
at scala.util.Either.fold(Either.scala:188)
at play.api.mvc.ActionRefiner.$anonfun$invokeBlock$3(Action.scala:522)
at scala.concurrent.Future.$anonfun$flatMap$1(Future.scala:302)
at scala.concurrent.impl.Promise.$anonfun$transformWith$1(Promise.scala:37)
at scala.concurrent.impl.CallbackRunnable.run(Promise.scala:60)
at akka.dispatch.BatchingExecutor$AbstractBatch.processBatch(BatchingExecutor.scala:55)
at akka.dispatch.BatchingExecutor$BlockableBatch.$anonfun$run$1(BatchingExecutor.scala:91)
at scala.runtime.java8.JFunction0$mcV$sp.apply(JFunction0$mcV$sp.java:12)
at scala.concurrent.BlockContext$.withBlockContext(BlockContext.scala:81)
at akka.dispatch.BatchingExecutor$BlockableBatch.run(BatchingExecutor.scala:91)
at akka.dispatch.TaskInvocation.run(AbstractDispatcher.scala:38)
at akka.dispatch.ForkJoinExecutorConfigurator$AkkaForkJoinTask.exec(ForkJoinExecutorConfigurator.scala:43)
at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260)
at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339)
at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979)
at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107)