本文整理汇总了Java中com.mashape.unirest.request.HttpRequest.asString方法的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest.asString方法的具体用法?Java HttpRequest.asString怎么用?Java HttpRequest.asString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.mashape.unirest.request.HttpRequest
的用法示例。
在下文中一共展示了HttpRequest.asString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doWork
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
private T doWork() {
try {
setupErrorHandlers();
WorkingContext workingContext = workingContext();
HttpRequest builtRequest = buildUnirest(workingContext)
.queryString(workingContext.getQueryParams())
.headers(workingContext.getHeaders()).header("Ocp-Apim-Subscription-Key", cognitiveContext.subscriptionKey);
if (!workingContext.getHttpMethod().equals(HttpMethod.GET) && workingContext().getPayload().size() > 0) {
buildBody((HttpRequestWithBody) builtRequest);
}
HttpResponse response;
if (typedResponse() == InputStream.class)
response = builtRequest.asBinary();
else
response = builtRequest.asString();
checkForError(response);
return postProcess(typeResponse(response.getBody()));
} catch (UnirestException | IOException e) {
throw new CognitiveException(e);
}
}
示例2: siaCommand
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
private HttpResponse<String> siaCommand(SiaCommand command, ImmutableMap<String, Object> params, String... extraCommand) {
try {
final HttpRequest httpRequest = command.unirest(path, extraCommand)
.header("User-Agent", "Sia-Agent")
.queryString(params);
return httpRequest.asString();
} catch (UnirestException e) {
throw new NoConnectException(e);
}
}
示例3: executeRequest
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
private static Object executeRequest(Method method, HttpRequest request) throws UnirestException {
HttpResponse response;
if (isString(returnTypeof(method))) {
response = request.asString();
} else {
response = request.asObject(returnTypeof(method));
}
return extractBody(method, response);
}
示例4: checkResponse
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
public static JsonNode checkResponse(HttpRequest request) throws ConsulException {
try {
HttpResponse<String> response = request.asString();
if (response.getStatus() >= 500) {
throw new ConsulException("Error Status Code: " + response.getStatus() + " body: " + response.getBody());
}
return parseJson(response.getBody());
} catch (UnirestException e) {
throw new ConsulException(e);
}
}
示例5: delete
import com.mashape.unirest.request.HttpRequest; //导入方法依赖的package包/类
@Override
public ActionResponse delete(String index, String type, String id) {
ActionResponse response = null;
try {
final HttpRequest request = Unirest.delete(getUrl(index, type, id, true));
if (StringUtils.isNotEmpty(username)) {
request.basicAuth(username, password);
}
final HttpResponse<String> result = request.asString();
final boolean isSucceeded = isSucceeded(result);
if (isSucceeded) {
final JsonNode body = new JsonNode(result.getBody());
response = new ActionResponse()
.succeeded(true)
.hit(new HitWrapper(
getFieldAsString(body, "_index"),
getFieldAsString(body, "_type"),
getFieldAsString(body, "_id"),
null));
}
else {
throw new ActionException(result.getBody());
}
}
catch (final UnirestException e) {
throw new ActionException(e);
}
return response;
}