本文整理汇总了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;
}
示例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());
}
}
示例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;
}
示例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));
}
示例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);
}
示例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);
}
示例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);
}
}
}
示例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()+"";
}
}
示例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;
}
示例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);
}
}
}
示例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"));
}
示例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;
}
}
示例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;
}
}
示例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);
}
示例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);
}