android retrofit2.00 表单是什么意思

Java Code Example retrofit.mime.FormUrlEncodedTypedOutput
Java Code Examples for retrofit.mime.FormUrlEncodedTypedOutput
The following are top voted examples for showing how to use
retrofit.mime.FormUrlEncodedTypedOutput. These examples are extracted from open source projects.
You can vote up the examples you like and your votes will be used in our system to product
more good examples.
+ Save this class to your library
RequestBuilder(Converter converter, RestMethodInfo methodInfo) {
this.converter =
paramNames = methodInfo.requestParamN
paramUsages = methodInfo.requestParamU
requestMethod = methodInfo.requestM
isSynchronous = methodInfo.isS
headers = new ArrayList&Header&();
if (methodInfo.headers != null) {
headers.addAll(methodInfo.headers);
queryParams = new StringBuilder();
relativeUrl = methodInfo.requestU
String requestQuery = methodInfo.requestQ
if (requestQuery != null) {
queryParams.append('?').append(requestQuery);
switch (methodInfo.requestType) {
case FORM_URL_ENCODED:
formBody = new FormUrlEncodedTypedOutput();
multipartBody =
body = formB
case MULTIPART:
formBody =
multipartBody = new MultipartTypedOutput();
body = multipartB
case SIMPLE:
formBody =
multipartBody =
// If present, 'body' will be set in 'setArguments' call.
throw new IllegalArgumentException(&Unknown request type: & + methodInfo.requestType);
RequestBuilder(Converter converter, RestMethodInfo methodInfo)
this.converter =
paramNames = methodInfo.requestParamN
paramUsages = methodInfo.requestParamU
requestMethod = methodInfo.requestM
isSynchronous = methodInfo.isS
isObservable = methodInfo.isO
headers = new ArrayList&Header&();
if (methodInfo.headers != null)
headers.addAll(methodInfo.headers);
queryParams = new StringBuilder();
relativeUrl = methodInfo.requestU
String requestQuery = methodInfo.requestQ
if (requestQuery != null)
queryParams.append('?').append(requestQuery);
switch (methodInfo.requestType)
case FORM_URL_ENCODED:
formBody = new FormUrlEncodedTypedOutput();
multipartBody =
body = formB
case MULTIPART:
formBody =
multipartBody = new MultipartTypedOutput();
body = multipartB
case SIMPLE:
formBody =
multipartBody =
// If present, 'body' will be set in 'setArguments' call.
throw new IllegalArgumentException(&Unknown request type: & + methodInfo.requestType);
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
Example 10
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );
Example 11
* Every time a method on the client interface is invoked, this method is
* going to get called. The method checks if the client has previously obtained
* an OAuth 2.0 bearer token. If not, the method obtains the bearer token by
* sending a password grant request to the server.
* Once this method has obtained a bearer token, all future invocations will
* automatically insert the bearer token as the &Authorization& header in
* outgoing HTTP requests.
public void intercept(RequestFacade request) {
// If we're not logged in, login and store the authentication token.
if (!loggedIn) {
// This code below programmatically builds an OAuth 2.0 password
// grant request and sends it to the server.
// Encode the username and password into the body of the request.
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField(&username&, username);
to.addField(&password&, password);
// Add the client ID and client secret to the body of the request.
to.addField(&client_id&, clientId);
to.addField(&client_secret&, clientSecret);
// Indicate that we're using the OAuth Password Grant Flow
// by adding grant_type=password to the body
to.addField(&grant_type&, &password&);
// The password grant requires BASIC authentication of the client.
// In order to do BASIC authentication, we need to concatenate the
// client_id and client_secret values together with a colon and then
// Base64 encode them. The final value is added to the request as
// the &Authorization& header and the value is set to &Basic &
// concatenated with the Base64 client_id:client_secret value described
String base64Auth = BaseEncoding.base64().encode(new String(clientId + &:& + clientSecret).getBytes());
// Add the basic authorization header
List&Header& headers = new ArrayList&Header&();
headers.add(new Header(&Authorization&, &Basic & + base64Auth));
// Create the actual password grant request using the data above
Request req = new Request(&POST&, tokenIssuingEndpoint, headers, to);
// Request the password grant.
Response resp = client.execute(req);
// Make sure the server responded with 200 OK
if (resp.getStatus() & 200 || resp.getStatus() & 299) {
// If not, we probably have bad credentials
throw new SecuredRestException(&Login failure: &
+ resp.getStatus() + & - & + resp.getReason());
// Extract the string body from the response
String body = IOUtils.toString(resp.getBody().in());
// Extract the access_token (bearer token) from the response so that we
// can add it to future requests.
accessToken = new Gson().fromJson(body, JsonObject.class).get(&access_token&).getAsString();
// Add the access_token to this request as the &Authorization&
// header.
request.addHeader(&Authorization&, &Bearer & + accessToken);
// Let future calls know we've already fetched the access token
loggedIn =
} catch (Exception e) {
throw new SecuredRestException(e);
// Add the access_token that we previously obtained to this request as
// the &Authorization& header.
request.addHeader(&Authorization&, &Bearer & + accessToken );

我要回帖

更多关于 retrofit 2.0 的文章

 

随机推荐