本文整理匯總了Java中com.squareup.okhttp.Response.message方法的典型用法代碼示例。如果您正苦於以下問題:Java Response.message方法的具體用法?Java Response.message怎麽用?Java Response.message使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.squareup.okhttp.Response
的用法示例。
在下文中一共展示了Response.message方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: handleResponse
import com.squareup.okhttp.Response; //導入方法依賴的package包/類
/**
* Handle the given response, return the deserialized object when the response is successful.
*
* @param <T> Type
* @param response Response
* @param returnType Return type
* @throws ApiException If the response has a unsuccessful status code or
* fail to deserialize the response body
* @return Type
*/
public <T> T handleResponse(Response response, Type returnType) throws ApiException {
if (response.isSuccessful()) {
if (returnType == null || response.code() == 204) {
// returning null if the returnType is not defined,
// or the status code is 204 (No Content)
return null;
} else {
return deserialize(response, returnType);
}
} else {
String respBody = null;
if (response.body() != null) {
try {
respBody = response.body().string();
} catch (IOException e) {
throw new ApiException(response.message(), e, response.code(), response.headers().toMultimap());
}
}
throw new ApiException(response.message(), response.code(), response.headers().toMultimap(), respBody);
}
}
示例2: requestNewToken
import com.squareup.okhttp.Response; //導入方法依賴的package包/類
private void requestNewToken(String grantType) throws IOException {
Map<String, String> localVarHeaderParams = new HashMap<>();
localVarHeaderParams.put("Accept", "application/json");
String method = "GET";
String[] localVarAuthNames = new String[] {};
List<Pair> localVarQueryParams = new ArrayList<>();
Map<String, Object> formParams = new HashMap<>();
localVarQueryParams.addAll(apiClient.parameterToPairs("", "grant_type", grantType));
if ("refresh_token".equals(grantType) || "password".equals(grantType)) {
String client = authenticationProperties.get(KEY_CLIENT);
String secret = authenticationProperties.get(KEY_SECRET);
byte[] creds = (client + ":" + secret).getBytes();
localVarHeaderParams.put("Authorization", "Basic " + Base64.getEncoder().encodeToString(creds));
}
if ("refresh_token".equals(grantType)) {
localVarQueryParams.addAll(apiClient.parameterToPairs("", "refresh_token", currentToken.getRefreshToken()));
}
if ("password".equals(grantType)) {
localVarHeaderParams.put("Content-Type", "multipart/form-data");
method = "POST";
formParams.put("username", authenticationProperties.get(KEY_USERNAME));
formParams.put("password", authenticationProperties.get(KEY_PASSWORD));
}
Response response = null;
try {
Request r = apiClient.buildRequest("/oauth/token", method, localVarQueryParams, null, localVarHeaderParams, formParams, localVarAuthNames, null);
logger.debug(r.toString());
Call call = apiClient.buildCall(r);
response = call.execute();
if (response.isSuccessful()) {
MyOAuthToken newToken = apiClient.deserialize(response, myOAuthTokenType);
newToken.computeExpirationDate();
currentToken = newToken;
} else {
throw new IOException("Unable to get an authentication token (" + response.code() + ") : Msg(" + response.message() + ") Body("
+ (response.body() != null ? response.body().string() : "") + ")");
}
} catch (ApiException e) {
throw new IOException(e);
} finally {
if (response != null) {
response.body().close();
}
}
}
示例3: flush
import com.squareup.okhttp.Response; //導入方法依賴的package包/類
@Override
public void flush() throws TTransportException {
Util.closeQuietly(mResponseBody);
mResponseBody = null;
RequestBody requestBody = new RequestBody() {
@Override
public MediaType contentType() {
if (mHeaders != null && mHeaders.containsKey("Content-Type")) {
return MediaType.parse(mHeaders.get("Content-Type"));
} else {
return MEDIA_TYPE_THRIFT;
}
}
@Override
public void writeTo(BufferedSink sink) throws IOException {
sink.write(mByteStore.getData(), 0, mByteStore.getBytesWritten());
}
};
try {
Request.Builder builder = new Request.Builder()
.url(mUrl)
.post(requestBody);
if (mHeaders != null) {
for (String name : mHeaders.keySet()) {
builder.header(name, mHeaders.get(name));
}
}
Response response = mHttpClient.newCall(builder.build()).execute();
if (response.code() != 200) {
throw new TTransportException("HTTP Response code: " + response.code() + ", message " + response.message());
}
mResponseBody = response.body().byteStream();
} catch (Exception e) {
throw new TTransportException(e);
} finally {
try {
mByteStore.reset();
} catch (IOException ignored) {
}
}
}
示例4: get
import com.squareup.okhttp.Response; //導入方法依賴的package包/類
public static StatusLine get(Response response) {
return new StatusLine(response.protocol(), response.code(), response.message());
}