-->

使用调度0.9.5后面代理?(use dispatch 0.9.5 behind proxy?)

2019-08-06 06:15发布

我想执行(在的IntelliJ IDE或SBT命令行)从后面代理这个很基本的调度片段:

import dispatch._
val svc = url("http://api.hostip.info/country.php")
val country = Http(svc > as.String)
println(country())

和所有我能得到的是一个例外:

java.net.ConnectException: Connection timed out: no further information to
    http://api.hostip.info/country.php java.util.concurrent.ExecutionException:
       java.net.ConnectException: Connection timed out: no further information 
            to http://api.hostip.info/country.php

我没有确凿的结果试图设置通常VM参数: -Dhttp.proxyHost= _my_proxy_host_ -Dhttp.proxyPort=80 ,仍然得到了同样的异常。

在另一方面,下面的代码片段也工作得很好:

import dispatch._
val svc = url("http://api.hostip.info/country.php") setProxyServer(new com.ning.http.client.ProxyServer(myproxyhost,80))
val country = Http(svc > as.String)
println(country())

因为它似乎并不十分美观,也不斯卡拉十岁上下,不知是否是真的是我应该在这种情况下做的。

任何帮助将受到欢迎,在此先感谢。

Answer 1:

http.proxyHosthttp.proxyPort如果你设置这个参数的使用方式:

-Dcom.ning.http.client.AsyncHttpClientConfig.useProxyProperties=true

Additionaly有参数:

-Dcom.ning.http.client.AsyncHttpClientConfig.proxy.user=user
-Dcom.ning.http.client.AsyncHttpClientConfig.proxy.password=password
-Dcom.ning.http.client.AsyncHttpClientConfig.proxy.protocol=NTLM


Answer 2:

看起来像我的问题是不是很令人振奋。

我做的皮条客我的图书馆的风格有点exercie:

package dispatch

package object ext {
    import com.ning.http.client.ProxyServer

  class DefaultPoxyVerbs(override val subject: Req) extends  ProxyVerbs

  object NoProxy extends ProxyServer("",0)

  object Proxy {
    def apply(host: String,port: Int) = new ProxyServer(host,port)
  }

  trait ProxyVerbs extends RequestVerbs {

    def through(proxy : ProxyServer) =
      if (NoProxy == proxy) subject else subject.setProxyServer(proxy)

    def ||>(proxy : ProxyServer) = through(proxy)

  }

  implicit def implyProxyVerbs(builder: Req) =
    new DefaultPoxyVerbs(builder)
}

现在我可以这样写:

  import dispatch._
  import dispatch.ext._

  val svc = url("http://api.hostip.info/country.php") through Proxy("blah blah blah",80)

  val country = Http(svc > as.String)
  println(country())

这是一点点的眼睛赏心悦目的和连贯的关于派遣API风格。

虽然这是一个有趣的练习,我还是不知道现在如果我最初使用API,我应该的方式也不知道为什么设置http.proxyHosthttp.proxyPort属性没有工作,因为它似乎对工作人 。



文章来源: use dispatch 0.9.5 behind proxy?