[Spray Client]: Facebook API returning the wrong content type
While in the Spray library , I tried to access the Facebook API:
val responseF: Future[HttpResponse] = pipeline(Get("http://graph.facebook.com/v2.1/facebook/picture?redirect=false"))
def receive = {
case _ =>
val originalSender = sender()
responseF onComplete{
case Success(response) =>
log.info(response.toString)
originalSender ! response.toString
log.info( """|Response for GET request
|status : {}
|headers: {}
|body : {}""".stripMargin,
response.status.value, response.headers.mkString("\n ", "\n ", ""), response.entity.asString)
case Failure(error) =>
log.error(error, "Could not get Facebook stuff")
originalSender ! "not working"
}
}
The main problem is that the content type of the response
Content-Type: text/javascript; charset=UTF-8
instead of the expectedapplication/json
What exactly is wrong with my request?
How Spray
largely depends on the type of content to parse, etc.
+3
source to share
1 answer
The simple solution was to just add an accept header, but I couldn't figure out how:
pipeline(
Get("http://graph.facebook.com/v2.1/facebook/picture?redirect=false").withHeaders(Accept(MediaTypes.`application/json`))
)
Thanks for the quick response to the goolge group . Finally, I got the correct content type.
+3
source to share