當前位置: 首頁>>代碼示例>>Java>>正文


Java Response.getReason方法代碼示例

本文整理匯總了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);
}
 
開發者ID:apiman,項目名稱:apiman-cli,代碼行數:19,代碼來源:ManagementApiUtil.java

示例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);
    }
}
 
開發者ID:kflauri2312lffds,項目名稱:Android_watch_magpie,代碼行數:34,代碼來源:SecuredRestBuilder.java


注:本文中的retrofit.client.Response.getReason方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。