Reqwest post response 200 but no json payload

I'm sending a post request as part of authentication. The request is formulated like this:

let client = reqwest::Client::new();                                                                                                            
client.post("https://listopf.auth0.com/oauth/token")                                                                                            
      .header(reqwest::header::CONTENT_TYPE, "application/json")
      .body(format!("{{\"grant_type\":\"authorization_code\",\"client_id\": \"{}\",\"client_secret\": \"mySecret\",\"code\": \"{}\",\"redirect_uri\": \"http://localhost:3030/app/callback\"}}", AUTH0ID, accesscode.code ))       
      .send()

The response I'm getting is

Ok(Response { url: “https://myapp.auth0.com/oauth/token”, status: 200, headers: {“date”: “Wed, 23 Jan 2019 14:35:42 GMT”, “content-type”: “application/json”, “content-length”: “1170”, “connection”: “keep-alive”, “x-auth0-requestid”: “862f8f4266d50e21ee26”, “x-ratelimit-limit”: “30”, “x-ratelimit-remaining”: “29”, “x-ratelimit-reset”: “1548254143”, “cache-control”: “private, no-store, no-cache, must-revalidate, post-check=0, pre-check=0”, “pragma”: “no-cache”, “strict-transport-security”: “max-age=15724800”, “x-robots-tag”: “noindex, nofollow, nosnippet, noarchive”} })

but I'm expecting a response that includes some json with fields like this

{
"access_token": "eyJz93a...k4laUWw",
"refresh_token": "GEbRxBN...edjnXbL",
"id_token": "eyJ0XAi...4faeEoQ",
"token_type": "Bearer"
}

Is this something I'm doing wrong with reqwest?

Response you're getting is the reqwest::Response object, containing mainly metadata (status code, final URI after redirects, etc.) To get the body of response, you must explicitly ask it for this, either with text() method, or by deserializing it with serde (see the link provided for details).

1 Like

Thanks. I got that the send() returned a Response from its signature

pub fn send(self) -> Result<Response>

but I didn't understand how to handle the Response. Because the fields are opaque in the docs I was hoping that printing to stdout would show me how the information was stored in the Response. Didn't understand the docs well enough. Thanks for enlightening me on what, in retrospect, is obvious.