scala-dispatch

use dispatch 0.9.5 behind proxy?

删除回忆录丶 提交于 2019-12-06 00:21:19
问题 I'm trying to execute (in IntelliJ IDE or from sbt command-line) this very basic dispatch snippet from behind a 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

Setting User-Agent Header in Scala with Databinders Dispatch Library

随声附和 提交于 2019-12-05 06:54:37
Does anyone know how to do this? You need to append your request with the header info, using the <:< operator. Like this : url("http://example.com") <:< Map("User-Agent" -> "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)") Just from reading the source, it looks like you're supposed to call http.client.params.setParameter("User-Agent","Cowbells") on your Http object. Have you tried this? This will work as well: url("http://example.com").addHeader("User-Agent", "Mozilla...") 来源: https://stackoverflow.com/questions/1394667/setting-user-agent-header-in-scala-with

Sequencing `Future`s with timeout

限于喜欢 提交于 2019-12-04 10:51:45
I utilized the TimeoutScheduler introduced at Scala Futures - built in timeout? . However, now my program does not terminate as before without TimeoutScheduler . I have two Future s: res1 and res2 . Both with a timeout of 15 seconds. In the end I sequence both Future s in order to shutdown the HTTP executor properly in the onComplete callback. Without using withTimeout the program terminates right after http.shutdown . But with using withTimeout is doesn't. Why? There must be some further futures... import java.net.URI import scala.util.{ Try, Failure, Success } import dispatch._ import org

How do I use Scala dispatch to get the URL returned in a 301 redirect?

↘锁芯ラ 提交于 2019-12-03 12:43:25
I am using Scala dispatch HTTP library, version 0.10.1. I make a request to a URL that returns an HTTP 301, permanent redirect. For example, http://wikipedia.com returns a 301 that redirects to http://www.wikipedia.org/ . How do I do I use dispatch to get the redirected URL? Following the tutorial, here's what I've done. import dispatch._, Defaults._ val svc = url("http://wikipedia.com") val r = Http(svc OK as.String) r() This throws a "Unexpected response status: 301" exception. Presumably I need to either query the r value for the redirected URL, or maybe specify some argument other than OK

Why does dispatch throw “java.net.ConnectException: General SSLEngine …” and “unexpected status” exceptions for a particular URL?

≡放荡痞女 提交于 2019-12-02 10:59:24
问题 I have the following non-working code: object Main extends App { import dispatch._ def test(address: String) = { Await.result(Http.default(url(address).GET OK as.String), Duration.Inf) } // This works fine val s1 = test("http://download.finance.yahoo.com/d/quotes.csv?s=MSFT&f=sohgbav") println(s1) // This throws Exception 1 val s2 = test("http://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo&datatype=csv") println(s2) // This throws Exception 2 val s3 =

Why does dispatch throw “java.net.ConnectException: General SSLEngine …” and “unexpected status” exceptions for a particular URL?

守給你的承諾、 提交于 2019-12-02 05:41:13
I have the following non-working code: object Main extends App { import dispatch._ def test(address: String) = { Await.result(Http.default(url(address).GET OK as.String), Duration.Inf) } // This works fine val s1 = test("http://download.finance.yahoo.com/d/quotes.csv?s=MSFT&f=sohgbav") println(s1) // This throws Exception 1 val s2 = test("http://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo&datatype=csv") println(s2) // This throws Exception 2 val s3 = test("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY_ADJUSTED&symbol=MSFT&apikey=demo