1

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!

Urist McDev
  • 498
  • 3
  • 14
em70
  • 6,088
  • 6
  • 48
  • 80

1 Answers1

4

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.

em70
  • 6,088
  • 6
  • 48
  • 80