Use 0.9.5 send per proxy?

I try to execute (in IntelliJ IDE or from sbt command line) this very basic fragment of sending due to proxy:

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

and all I can get is an exception:

 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 

I tried without the final result to set the usual vm parameters: -Dhttp.proxyHost= _my_proxy_host_ -Dhttp.proxyPort=80 and still got the same exception.

On the other hand, the following snippet works well:

 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()) 

Since it doesn't look pretty aesthetic and scala -ish, I wonder if this is really what I should do in that case.

Any help would be appreciated, thanks in advance.

+6
source share
2 answers

http.proxyHost and http.proxyPort will be used if you set this parameter:

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

Extra options:

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

It seems my question was not very inspiring.

I did a bit of pimping my library style:

 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) } 

Now I can write:

  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()) 

which is a little more enjoyable and consistent in regards to the api style for submitting.

While this was an interesting exercise, I still don’t know if I initially used the api as I expected, and why the http.proxyHost and http.proxyPort did not work, as it seems to work for others .

+4
source

All Articles