【发布时间】:2013-10-24 20:22:14
【问题描述】:
我似乎无法使用 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 对象的标头。
【问题讨论】:
标签: scala post cookies scala-dispatch