Dispatch を使用して Cookie を設定できないようです。サーバーは、送信しようとしたセッション ID が正しく送信されなかったことを意味する新しいセッション ID を再送信します。コードは次のとおりです。
val domain = "myhost.com"
val host_req = host(domain).secure
val request = host_req / "path" / "path"
def post = request << Map("key" -> "SomeValue")
val response: Either[Throwable, Map[String, String]] =
Http(post OK asHeaders).either()
//The cookie comes down in the form "Set-Cookie: SESSIONID=<somesession>; Path=/path/; HttpOnly"
//successfully retrieves the session id...
val sessionId = getSessionId(response)
println(sessionId)
val sessionCookie = new com.ning.http.client.Cookie(domain, "SESSIONID", sessionId, "/path/", -1, true)
request.POST.addCookie(sessionCookie)
def establishPost = request << Map("key" -> "SomeValue")
establishPost.addCookie(sessionCookie)
val establishResponse: Either[Throwable, Map[String, String]] =
Http(establishPost OK asHeaders).either()
//Server sends down new SESSIONID...
//sessionId != getSEssionId(establishPost)
これは Dispatch の最新バージョンを使用しています。私は Scala を学びながら学習しようとしていますが、どのようにすればよいか分からないのは、リクエストとして送信される前に、 EstablishPost オブジェクトのヘッダーを検査することだけです。