当前位置: 首页>>代码示例>>Java>>正文


Java HttpRequest.asString方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:CognitiveJ,项目名称:cognitivej,代码行数:23,代码来源:RestAction.java

示例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);
    }
}
 
开发者ID:MineboxOS,项目名称:minebox,代码行数:11,代码来源:SiaUtil.java

示例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);
    }
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:13,代码来源:Rest.java

示例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);
     }
}
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:12,代码来源:ConsulChain.java

示例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;
}
 
开发者ID:apache,项目名称:zeppelin,代码行数:32,代码来源:HttpBasedClient.java


注:本文中的com.mashape.unirest.request.HttpRequest.asString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。