scala-dispatch

Correct mvn version for dispatch.databinder.net

徘徊边缘 提交于 2020-01-04 05:25:50
问题 The last version of the library dispatch.databinder.net is 0.9.5, according to the website. What is the correct mvn dependency? <dependency> <groupId>net.databinder.dispatch</groupId> <artifactId>core_2.10</artifactId> <version>0.9.1</version> </dependency> or <dependency> <groupId>net.databinder.dispatch</groupId> <artifactId>dispatch-core_2.10</artifactId> <version>0.9.5</version> </dependency> or something else? and how to find out this in general? 回答1: Since the website says

Return exact response/header?

时光总嘲笑我的痴心妄想 提交于 2019-12-24 00:55:38
问题 From the client-side of a webapp, I hit a server-side route which is just a wrapper for a third-party API. Using dispatch, I am trying to make that server-side request return the exact header and response of the third-party API to the client-side AJAX call. When I do this: val req = host("third-pary.api.com, 80) val post = req.as("user", "pass") / "route" << Map("key" -> "akey", "val" -> "aval") Http(post > as.String) I always see a 200 response returned to the AJAX call (kind of expectedly).

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

不羁岁月 提交于 2019-12-21 04:20:33
问题 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

Scala dispatch stream response line by line

可紊 提交于 2019-12-14 01:23:48
问题 I am attempting to use Scala dispatch but been both a Scala neewbie and the face that Dispatch api is symbol crazy Im confused on how I can stream a large http response and process it line by line. Any help would be appreciated. Cheers, Chris. Note: This isn't working for me: Http(url(Config.publisherUrl) > as.stream.Lines(line => println(line))) The lines are never printed. Edit: The lines were being printed, but only when there was more than one line in the response. The issue seems to be

Scala Dispatch library: how to handle connection failure or timeout?

允我心安 提交于 2019-12-13 11:43:34
问题 I've been using the Databinder Dispatch library in a client for a simple REST-ish API. I know how to detect if I get an HTTP response with an error status: Http x (request) { case (200, _, _, content) => successResult(content()) case (404, _, _, _) => notFoundErrorResult case (_, _, _, _) => genericErrorResult } But how can I distinguish an error response from a failure to get any response at all, because of an invalid domain or failure to connect? And is there any way to implement a timeout

Where to put dispatch.Http.shutdown() in case of cascading Http calls

这一生的挚爱 提交于 2019-12-12 01:03:53
问题 At Where to put dispatch.Http.shutdown() I asked where to place the call to dispatch.Http.shutdown() if there are n independent Http calls. Those n independent calls, however, are all on the same "level". How about cascading Http calls , whereas outer1 and outer2 are independent of each other (like in my former question), the inner calls, however, depend on the result of the respective outer call. val outer1 = dispatch.Http(... request1 ...) val outer2 = dispatch.Http(... request2 ...) outer1

Scala Dispatch Simple Get Request

岁酱吖の 提交于 2019-12-11 09:03:02
问题 I am trying to execute a Simple GET request with Scala Dispatch, however I am erroring out with a 404 error. Unexpected response status: 404 Here is a example that works: https://www.google.com/finance/info?infotype=infoquoteall&q=tsla,goog But am I amunsure of where my error is in my code import dispatch._ , Defaults._ object Main extends App { //concats a the proper uri together to send to google finance def composeUri ( l:List[String]) = { def google = host("google.com").secure def

Where to put dispatch.Http.shutdown()

落花浮王杯 提交于 2019-12-10 14:56:31
问题 where to place the call to dispatch.Http.shutdown() if there are n independent Http calls like, for example: import com.typesafe.scalalogging.slf4j.Logging import org.json4s._ import org.json4s.native.JsonMethods._ import scala.util.{ Failure, Success } object Main extends App with Logging { logger.debug("github.cli") // GET /users/defunkt: `curl https://api.github.com/users/defunkt` val host: dispatch.Req = dispatch.host("api.github.com").secure val request: dispatch.Req = host / "users" /

Setting User-Agent Header in Scala with Databinders Dispatch Library

血红的双手。 提交于 2019-12-07 02:15:37
问题 Does anyone know how to do this? 回答1: 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)") 回答2: 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? 回答3: This will work as well: url("http://example.com").addHeader(

Sequencing `Future`s with timeout

本秂侑毒 提交于 2019-12-06 05:12:04
问题 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