scalaj etag 获取无法解析

scalaj etag get can't parse

使用 scalaj.http 2.4 我无法为这个简单的调用获得 If-None-Match etag 的正确代码:

import scalaj.http.Http
object EtagTest extends App {
  val firstResponse = Http("https://api.github.com/users/octocat/orgs")
  // get correct etag ...
  val response = Http("https://api.github.com/users/octocat/orgs").header("If-None-Match", "\"98f0c1b396a4e5d54f4d5fe561d54b44\"").asString
  println(response.code)
}

我期待 304 Not Modified 但我得到 200

我尝试了以下方法,它对我有用。看起来您通过此程序获得的 ETag 并不是您在程序中硬编码的 ETag。奇怪的是,当我向它发送 cURL 请求时,返回的 ETag 是您硬编码的那个。

import scalaj.http.Http

object ETagTest extends App {
  val firstResponse = Http("https://api.github.com/users/octocat/orgs").asString
  val response = Http("https://api.github.com/users/octocat/orgs").header("If-None-Match", firstResponse.header(key = "ETag").get).asString
  println(response.code)
  println(response.header(key = "ETag").get)
}

上面的输出:

304
"80b190627d4c87e9a37c34e20ea246a1"