本文整理汇总了Java中retrofit.client.Response.getReason方法的典型用法代码示例。如果您正苦于以下问题:Java Response.getReason方法的具体用法?Java Response.getReason怎么用?Java Response.getReason使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类retrofit.client.Response
的用法示例。
在下文中一共展示了Response.getReason方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: httpError
import retrofit.client.Response; //导入方法依赖的package包/类
private static void httpError(int expectedStatus, Response response) throws CommandException {
if (null == response) {
throw new IllegalArgumentException("Response was null");
}
// obtain response body
String body = null;
if (null != response.getBody()) {
try (InputStream errStream = response.getBody().in()) {
body = CharStreams.toString(new InputStreamReader(errStream));
} catch (IOException ignored) {
}
}
throw new CommandException("HTTP " + response.getStatus() + " "
+ response.getReason() + " but expected " + expectedStatus + ":\n" + body);
}
示例2: intercept
import retrofit.client.Response; //导入方法依赖的package包/类
@Override
public void intercept(RequestFacade request) {
if (!loggedIn) {
try {
FormUrlEncodedTypedOutput to = new FormUrlEncodedTypedOutput();
to.addField("username", username);
to.addField("password", password);
to.addField("grant_type", "password");
String base64Auth = BaseEncoding.base64().encode(new String(clientId + ":" + clientSecret).getBytes());
List<Header> headers = new ArrayList<Header>();
headers.add(new Header("Authorization", "Basic " + base64Auth));
Request req = new Request("POST", tokenIssuingEndpoint, headers, to);
Response resp = client.execute(req);
if (resp.getStatus() < 200 || resp.getStatus() > 299) {
throw new SecuredRestException("Login failure: "
+ resp.getStatus() + " - " + resp.getReason());
} else {
String body = IOUtils.toString(resp.getBody().in());
accessToken = new Gson().fromJson(body, JsonObject.class).get("access_token").getAsString();
request.addHeader("Authorization", "Bearer " + accessToken);
loggedIn = true;
}
} catch (Exception e) {
throw new SecuredRestException(e);
}
} else {
request.addHeader("Authorization", "Bearer " + accessToken);
}
}