em70
em70

Reputation: 6081

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

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!

Upvotes: 1

Views: 1003

Answers (1)

em70
em70

Reputation: 6081

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.

Upvotes: 4

Related Questions