Question

I'm trying to download the response of an HTTP GET request as an Array[Byte] in Scala using dispatch, but the documentation is not helping and online searches didn't turn out to be helpful. Additionally, I need to retrieve the value of a header in the response.

Could anyone please provide a working snippet, possibly with a custom header?

Thanks in advance!

Was it helpful?

Solution

Came up with my own way:

val (someHeaderVal, buf) = Http x (url(fileUrl) <:< Map("ACustomHeader" -> "MyValue") >:+ {
  (headers, req) => req >> {
    stream => (headers("ResponseCustomHeader").head, IOUtils.toByteArray(stream))
  }
})

This seems to work just fine.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top