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


Java HttpRequest.body方法代碼示例

本文整理匯總了Java中com.github.kevinsawicki.http.HttpRequest.body方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpRequest.body方法的具體用法?Java HttpRequest.body怎麽用?Java HttpRequest.body使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.github.kevinsawicki.http.HttpRequest的用法示例。


在下文中一共展示了HttpRequest.body方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: wsConvert

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
private double wsConvert(double amount, String fromUnifiedSymbol, String toUnifiedSymbol)
		throws HttpRequestException, Exception {
	String fromUnit = prep(fromUnifiedSymbol);
	String toUnit = prep(toUnifiedSymbol);

	String conversionUrl = amount + "/" + FROM + fromUnit + "/" + TO + toUnit;
	String url = BASE_URL + conversionUrl;
	System.out.println(url);

	HttpRequest request = HttpRequest.get(url).accept("application/json");

	if (request.code() != 200) {
		throw new Exception("Web service call returned " + request.code());
	}

	double decimal = 0;
	String body = request.body();
	if (body.startsWith("{")) {
		WebServiceConversion wsResponse = gson.fromJson(body, WebServiceConversion.class);

		decimal = getResultQuantity(wsResponse);
	} else {
		throw new Exception(body);
	}
	return decimal;
}
 
開發者ID:point85,項目名稱:caliper,代碼行數:27,代碼來源:TestUnifiedCode.java

示例2: getUserInfo

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Gets user information from the UserInfo endpoint.
 * @param token an idToken or accessToken associated to the end-user.
 * @param classOfT the class used to deserialize the user info into.
 * @return the parsed user information.
 * @throws IOException for an error response
 */
public  <T> T getUserInfo(String token,  Class<T> classOfT) throws IOException {
    String url = userInfoEndpoint;
    if (extras != null) {
        url = HttpRequest.append(userInfoEndpoint, extras);
    }

    HttpRequest request = new HttpRequest(url, HttpRequest.METHOD_GET);
    request.authorization("Bearer " + token).acceptJson();

    if (request.ok()) {
        String jsonString = request.body();
        return new Gson().fromJson(jsonString, classOfT);
    } else {
        throw new IOException(request.message());
    }
}
 
開發者ID:kalemontes,項目名稱:OIDCAndroidLib,代碼行數:24,代碼來源:OIDCRequestManager.java

示例3: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Override this method to perform a computation on a background thread. The
 * specified parameters are the parameters passed to {@link #execute}
 * by the caller of this task.
 *
 * This method can call {@link #publishProgress} to publish updates
 * on the UI thread.
 *
 * @param comicNumber The parameters of the task.
 * @return A result, defined by the subclass of this task.
 * @see #onPreExecute()
 * @see #onPostExecute
 * @see #publishProgress
 */
@Override protected Comic doInBackground(Integer... comicNumber) {
    // Should only ever be a single comic number, so let's enforce it.
    if (comicNumber != null && comicNumber.length == 1) {
        HttpRequest request = HttpRequest.get(ComicUtil.getComicApiUrl(comicNumber[0]));
        if (request.code() == 200) {
            String response = request.body();
            request.disconnect();
            Gson gson = new Gson();
            Comic comicResponse = gson.fromJson(response, Comic.class);

            return comicResponse;
        } else {
            request.disconnect();
            return null;
        }
    }
    return null;
}
 
開發者ID:DavidTPate,項目名稱:XKCD-Reader,代碼行數:33,代碼來源:ComicFragment.java

示例4: test02

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
@Test
public void test02() throws Exception {
    //49
    ObjectMapper mapper = new ObjectMapper();
    List<String> ret = new ArrayList<>();
    String url = "https://xueqiu.com/stock/cata/stocklist.json?page=";
    String param = "&size=100&order=desc&orderby=percent&type=11%2C12&_=1461851096446";
    for (int i = 1; i <= 50; i++) {
        String dest = url + i + param;
        HttpRequest req = HttpRequest.get(dest);
        req.header("Cookie", "xq_a_token=93b9123bccf67168e3adb0c07d89b9e1f6cc8db6;");
        String body = req.body();
        ret.add(body);

        JsonNode jsonNode = mapper.readTree(body);
        JsonNode stocks = jsonNode.get("stocks");
        stocks.forEach(st->{
            Stock stock = null;
            try {
                stock = mapper.readValue(st.toString(), Stock.class);
                DaoUtil.dao.insert(stock);
            } catch (Exception e) {
                e.printStackTrace();
            }

        });
        Thread.sleep(500);
        System.out.println("fetch url " + dest + " result " + body);

    }
    System.out.println("final result---> " + mapper.writeValueAsString(ret));

}
 
開發者ID:jt120,項目名稱:take,代碼行數:34,代碼來源:LoginTest.java

示例5: test05

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
@Test
public void test05() throws Exception {

    HttpRequest request = HttpRequest.get("http://push3.gtimg.cn/q=sz300507,sz002629,sh603029,sz000099,sz300277,sz002684,sh600538,sz002097,sz002795,sh603868,sz300508,sz002729,sz000665,sz300073,sz300481,sz300097,sz002793,sh603701,sh603726,sh600073,sz300466,sz300509,sz002106,sh603822,sz300249&m=push&r=864212903");
    String body = request.body();
    System.out.println(body);
}
 
開發者ID:jt120,項目名稱:take,代碼行數:8,代碼來源:LoginTest.java

示例6: forceDeploy

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
public void forceDeploy(Environment env, String userName) {
    log.info("deploying environment id: " + env.getId());
    HttpRequest request = HttpRequest.post("http://transistor." + cmsApiHost
            + "/transistor/rest/environments/" + env.getId() + "/deployments/deploy")
            .contentType("application/json").header("X-Cms-User", userName).send("{}");
    String response = request.body();
    log.info("OO response : " + response);
}
 
開發者ID:oneops,項目名稱:oneops,代碼行數:9,代碼來源:OneOpsFacade.java

示例7: makeRequest

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, String body, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);
    String cookies = accountManager.getCookies(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken, cookies);
    if (body != "") {
        request.send(body);
    }

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, body, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}
 
開發者ID:tdb-alcorn,項目名稱:defect-party,代碼行數:41,代碼來源:APIUtility.java

示例8: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
protected String doInBackground(String... params) {
    HttpRequest request = HttpRequest.get(UPLOAD_URL,true, params);
    Log.d("jabe", "開始上傳 : " + request.url());
    if (request.code() == 200) {
        return request.body();
    } else {
        return request.code()+"";
    }
}
 
開發者ID:jabelai,項目名稱:location-phonegap,代碼行數:10,代碼來源:LocationCacheService.java

示例9: getAccessToken

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
public static String getAccessToken(String username, String password, String clientId, String clientSecret) throws Exception {

        HttpRequest req = HttpRequest.post("https://www.reddit.com/api/v1/access_token")
                .basic(clientId, clientSecret)
                .header("User-Agent", "reddit-history/0.1 by " + username)
                .form("grant_type", "password")
                .form("username", username)
                .form("password", password);

        String body = req.body();
        log.info(body);
        String accessToken = convertJsonToNode(body).get("access_token").asText();

        return accessToken;
    }
 
開發者ID:dessalines,項目名稱:reddit-history,代碼行數:16,代碼來源:App.java

示例10: makeRequest

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
private static String makeRequest(OIDCAccountManager accountManager, String method, String url, Account account,
                                  boolean doRetry, AccountManagerCallback<Bundle> callback)
        throws IOException, UserNotAuthenticatedWrapperException, AuthenticatorException, OperationCanceledException {


    String accessToken = accountManager.getAccessToken(account, callback);

    // Prepare an API request using the accessToken
    HttpRequest request = new HttpRequest(url, method);
    request = prepareApiRequest(request, accessToken);

    if (request.ok()) {
        return request.body();
    } else {
        int code = request.code();

        String requestContent = "empty body";
        try {
            requestContent = request.body();
        } catch (HttpRequest.HttpRequestException e) {
            //Nothing to do, the response has no body or couldn't fetch it
            e.printStackTrace();
        }

        if (doRetry && (code == HTTP_UNAUTHORIZED || code == HTTP_FORBIDDEN ||
                (code == HTTP_BAD_REQUEST && (requestContent.contains("invalid_grant") || requestContent.contains("Access Token not valid"))))) {
            // We're being denied access on the first try, let's renew the token and retry
            accountManager.invalidateAuthTokens(account);

            return makeRequest(accountManager, method, url, account, false, callback);
        } else {
            // An unrecoverable error or the renewed token didn't work either
            throw new IOException(request.code() + " " + request.message() + " " + requestContent);
        }
    }
}
 
開發者ID:kalemontes,項目名稱:OIDCAndroidLib,代碼行數:37,代碼來源:APIUtility.java

示例11: getResult

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Get statistic info from server
 *
 * @throws NetworkException
 */
public static Emotions getResult(String type) throws NetworkException, JSONException
{
	String url = API_PART_RESULT_URL + "/" + type;
	HttpRequest request = new HttpRequest(getAbsoluteUrl(url), HttpRequest.METHOD_GET);
	request(request);
	JSONObject json = new JSONObject(request.body());
	return new Emotions(json.getJSONArray("emotionVotes"));
}
 
開發者ID:PacteraMobile,項目名稱:pacterapulse-android,代碼行數:14,代碼來源:NetworkHelper.java

示例12: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Override this method to perform a computation on a background thread. The
 * specified parameters are the parameters passed to {@link #execute}
 * by the caller of this task.
 *
 * This method can call {@link #publishProgress} to publish updates
 * on the UI thread.
 *
 * @param params The parameters of the task.
 * @return A result, defined by the subclass of this task.
 * @see #onPreExecute()
 * @see #onPostExecute
 * @see #publishProgress
 */
@Override protected Comic doInBackground(Void... params) {
    HttpRequest request = HttpRequest.get(Constants.API.LATEST_COMIC_ENDPOINT);
    if (request.code() == 200) {
        String response = request.body();
        request.disconnect();
        Gson gson = new Gson();
        Comic comicResponse = gson.fromJson(response, Comic.class);

        return comicResponse;
    } else {
        request.disconnect();
        return null;
    }
}
 
開發者ID:DavidTPate,項目名稱:XKCD-Reader,代碼行數:29,代碼來源:ComicFragmentActivity.java

示例13: doInBackground

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
/**
 * Override this method to perform a computation on a background thread. The
 * specified parameters are the parameters passed to {@link #execute}
 * by the caller of this task.
 *
 * This method can call {@link #publishProgress} to publish updates
 * on the UI thread.
 *
 * @param params The parameters of the task.
 * @return A result, defined by the subclass of this task.
 * @see #onPreExecute()
 * @see #onPostExecute
 * @see #publishProgress
 */
@Override protected Comic doInBackground(Void... params) {
    HttpRequest request = HttpRequest.get("http://xkcd.com/info.0.json");
    if (request.code() == 200) {
        String response = request.body();
        request.disconnect();
        Gson gson = new Gson();
        Comic comicResponse = gson.fromJson(response, Comic.class);

        return comicResponse;
    } else {
        request.disconnect();
        return null;
    }
}
 
開發者ID:DavidTPate,項目名稱:XKCD-Reader,代碼行數:29,代碼來源:CurrentComic.java

示例14: _save

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
/**
 *
 * @param client    The communication client
 * @return          The details of the subscription as a result of the save
 * @throws Exception
 */
public Response<Subscription> _save(Client client) throws Exception {
    HttpRequest request = this.isPersisted() ?
            client.put("subscriptions/" + id, this.asHash()) :
            client.post("subscriptions", this.asHash());
    return new Response<Subscription>(request.code(), request.body(), Subscription.class);
}
 
開發者ID:kfrancis,項目名稱:Chargify.Java,代碼行數:13,代碼來源:Subscription.java

示例15: _save

import com.github.kevinsawicki.http.HttpRequest; //導入方法依賴的package包/類
public Response<Customer> _save(Client client) throws Exception {
    HttpRequest request = this.isPersisted() ?
            client.put("customers/" + id, this.asHash()) :
            client.post("customers", this.asHash());

    return new Response<Customer>(request.code(), request.body(), Customer.class);
}
 
開發者ID:kfrancis,項目名稱:Chargify.Java,代碼行數:8,代碼來源:Customer.java


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