本文整理匯總了Java中com.mashape.unirest.http.HttpResponse.getBody方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.getBody方法的具體用法?Java HttpResponse.getBody怎麽用?Java HttpResponse.getBody使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.mashape.unirest.http.HttpResponse
的用法示例。
在下文中一共展示了HttpResponse.getBody方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getAsJSONArray
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
/**
* @return The json array get by performing request.
*/
public JSONArray getAsJSONArray() {
JSONArray json;
try {
HttpResponse<JsonNode> response = request.asJson();
checkRateLimit(response);
handleErrorCode(response);
JsonNode node = response.getBody();
if (!node.isArray()) {
handleErrorResponse(node.getObject());
throw new UnirestException("The request returns a JSON Object. Json: "+node.getObject().toString(4));
} else {
json = node.getArray();
}
} catch (UnirestException e) {
throw new JSONException("Error Occurred while getting JSON Array: "+e.getLocalizedMessage());
}
return json;
}
示例2: retrieveAllFiles
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
public static List<String> retrieveAllFiles(String auth, String folder) throws IOException, UnirestException {
List<String> lis= new LinkedList<String>();
HttpResponse<JsonNode> jsonResponse = Unirest.get("https://www.googleapis.com/drive/v2/files/root/children?q=title='"+folder+"'").header("Authorization","Bearer "+auth).asJson();
JSONObject jsonObject= new JSONObject(jsonResponse.getBody());
JSONArray array = jsonObject.getJSONArray("array");
for(int i=0;i<array.length();i++){
JSONArray jarray=array.getJSONObject(i).getJSONArray("items");
int j=jarray.length();
while(j>0){
String id=jarray.getJSONObject(0).getString("id");
auxRetrieveAllFiles(lis,auth,"https://www.googleapis.com/drive/v2/files?includeTeamDriveItems=false&pageSize=500&q='"+id+"'%20in%20parents"+"&key="+ MISConfig.getGoogle_api(),id);
j--;
}
}
return lis;
}
示例3: getList
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
/**
* Get List of records of response.
*
* @param response
* @return
*/
private List<T> getList(HttpResponse<Records> response) {
final Records records = response.getBody();
final List<T> list = new ArrayList<>();
for (Map<String, Object> record : records.getRecords()) {
T item = null;
try {
item = transform(record, this.type.newInstance());
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
LOG.error(e.getMessage(), e);
}
list.add(item);
}
return list;
}
示例4: performRequest
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
/**
* Performs requests
* @return HttpCode, the response status
*/
public HttpCode performRequest() {
try {
HttpResponse<JsonNode> response = request.asJson();
checkRateLimit(response);
handleErrorCode(response);
JsonNode node = response.getBody();
if (node != null && !node.isArray()) {
handleErrorResponse(node.getObject());
}
return HttpCode.getByKey(response.getStatus());
} catch (UnirestException e) {
throw new RuntimeException("Fail to perform http request!");
}
}
示例5: downloadLatestMetadataZip
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
protected InputStream downloadLatestMetadataZip(String token) throws UnirestException {
final HttpResponse<InputStream> response = Unirest.get(metadataUrl + "file/latestMeta")
.header("X-Auth-Token", token)
.asBinary();
if (response.getStatus() == 404) return null;
return response.getBody();
}
示例6: ensureStatusOk
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
private static void ensureStatusOk(HttpResponse<String> response) throws ClientErrorException,
ServerErrorException, OtherCommunicationException {
int responseStatus = response.getStatus();
if (isClientError(responseStatus)) {
throw new ClientErrorException(response.getBody());
} else if (isServerError(responseStatus)) {
throw new ServerErrorException(response.getStatusText());
} else if (isOtherErrorResponse(responseStatus)) {
throw new OtherCommunicationException(response.getStatusText());
}
}
示例7: myAddress
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
public String myAddress() {
final HttpResponse<String> string = siaCommand(SiaCommand.ADDRESS, ImmutableMap.of());
if (walletIsLocked(string)) {
return null;
}
final JSONObject jsonObject = new JSONObject(string.getBody());
return jsonObject.getString("address");
}
示例8: sendAction
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
String sendAction(String action) throws
ClientErrorException, ServerErrorException, OtherCommunicationException {
try {
String encodedPath = URLEncoder.encode(this.journeyId, "UTF-8");
String url = String.format("http://%s:%d/action/%s/%s", this.url, port, action, encodedPath);
HttpResponse<String> response = Unirest.post(url)
.header("Accept", this.acceptHeader)
.header("Accept-Charset", "UTF-8")
.asString();
ensureStatusOk(response);
return response.getBody();
} catch (UnirestException | UnsupportedEncodingException e ) {
throw new OtherCommunicationException("Could not perform POST request",e);
}
}
示例9: testIsTestRepositoryAvailable
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
@Test
public void testIsTestRepositoryAvailable() throws IOException, UnirestException {
HttpResponse<RepositoryContainer> response = Unirest.get(seRepoTestServer.LOCALHOST_REPOS)
.asObject(RepositoryContainer.class);
RepositoryContainer repos = response.getBody();
assertTrue(repos.getRepositories().stream().map(Repository::getName).collect(Collectors.toList
()).contains(TestDataProvider.TEST_REPO));
}
示例10: login
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
@Override
public UserProfile login(PlayerLogin playerLogin) {
try {
HttpResponse<UserProfile> userProfileResponse = Unirest.post(config.getBaseUrl() + "/mc/player/login")
.header("x-access-token", config.getAuthToken())
.header("accept", "application/json")
.header("Content-Type", "application/json")
.body(playerLogin)
.asObject(UserProfile.class);
return userProfileResponse.getBody();
} catch (UnirestException e) {
e.printStackTrace();
return null;
}
}
示例11: loadmap
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
@Override
public MapLoadResponse loadmap(Map map) {
try {
HttpResponse<MapLoadResponse> mapLoadResponse = Unirest.post(config.getBaseUrl() + "/mc/map/load")
.header("x-access-token", config.getAuthToken())
.header("accept", "application/json")
.header("Content-Type", "application/json")
.body(map)
.asObject(MapLoadResponse.class);
return mapLoadResponse.getBody();
} catch (UnirestException e) {
e.printStackTrace();
return null;
}
}
示例12: loadMatch
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
@Override
public MatchInProgress loadMatch(MatchLoadRequest matchLoadRequest) {
try {
HttpResponse<MatchInProgress> userProfileResponse = Unirest.post(config.getBaseUrl() + "/mc/match/load")
.header("x-access-token", config.getAuthToken())
.header("accept", "application/json")
.header("Content-Type", "application/json")
.body(matchLoadRequest)
.asObject(MatchInProgress.class);
return userProfileResponse.getBody();
} catch (UnirestException e) {
e.printStackTrace();
return null;
}
}
示例13: extractBody
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
private static Object extractBody(Method method, HttpResponse response) {
if (isString(returnTypeof(method)) && response.getBody() != null) {
return trimEnclosingQuotes(response.getBody().toString());
} else {
return response.getBody();
}
}
示例14: deleteEffects
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
/**
* Deletes multiple effects and removes them from the device
*
* @param effectIds the {@link EffectIds}
* @return the result
* @throws UnirestException
*/
public ResponseResult deleteEffects(EffectIds effectIds) throws UnirestException {
checkInitialized();
HttpResponse<ResponseResult> response = Unirest
.put(this.session.getUri() + "/effect")
.body(effectIds)
.asObject(ResponseResult.class);
return response.getBody();
}
示例15: send
import com.mashape.unirest.http.HttpResponse; //導入方法依賴的package包/類
/**
* Send the payload to Discord.
*
* @throws WebhookException the webhook exception
*/
public void send() throws WebhookException {
this.obj.put("embeds", new JSONArray().put(this.embed));
try {
HttpResponse<JsonNode> response = Unirest.post(this.webhookUrl).header("Content-Type", "application/json").body(this.obj).asJson();
try {
if (response.getBody() == null || response.getBody().getObject().get("embeds") == null) throw new JSONException("Expected.");
throw new WebhookException(response.getBody().getObject().toString(2));
} catch (JSONException ignored) {}
} catch (UnirestException e) { e.printStackTrace(); }
}