Getting an HTTP response as Array[Byte] with Scala and Dispatch

1k views Asked by At

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!

1

There are 1 answers

0
em70 On BEST ANSWER

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.