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


Java HttpRequest类代码示例

本文整理汇总了Java中com.mashape.unirest.request.HttpRequest的典型用法代码示例。如果您正苦于以下问题:Java HttpRequest类的具体用法?Java HttpRequest怎么用?Java HttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpRequest类属于com.mashape.unirest.request包,在下文中一共展示了HttpRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: requestHttp

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
/**
 * Using the HttpMethod to return a http request.
 * @param params Parameters to be replaced.
 * @return The http request
 */
private HttpRequest requestHttp(Object... params) {
    String processedPath = processPath(params);

    HttpRequest request = null;
    switch (path.getMethod()) {
        case GET:
            request = Unirest.get(processedPath); break;
        case HEAD:
            request = Unirest.head(processedPath); break;
        case POST:
            request = Unirest.post(processedPath); break;
        case PUT:
            request = Unirest.put(processedPath); break;
        case PATCH:
            request = Unirest.patch(processedPath); break;
        case DELETE:
            request = Unirest.delete(processedPath); break;
        case OPTIONS:
            request = Unirest.options(processedPath); break;
    }
    processRequest(request);
    this.request = request;
    return request;
}
 
开发者ID:AlienIdeology,项目名称:J-Cord,代码行数:30,代码来源:Requester.java

示例2: buildQueryStringFromHeaders

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
private static HttpRequest buildQueryStringFromHeaders(
        List<String> headers,
        Object[] args,
        int startAt,
        HttpRequest request) {
    if (headers.size() > 0) {
        int i = startAt;
        for (String header : headers) {
            String headerValue = "";
            if (args[i] != null) {
                if (!isPrimitiveOrString(args[i].getClass())) {
                    headerValue = new UnirestJacksonObjectMapper().writeValue(args[i]);
                } else {
                    headerValue = args[i].toString();
                }
            }
            request = request.queryString(header, headerValue);
            i++;
        }
    }
    return request;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:23,代码来源:Rest.java

示例3: getServerInfo

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
public ServerInfo getServerInfo(Filter filter, Long minLastUpdate) {
    try {
        HttpRequest req = Unirest.get(url("/info"));
        if (filter.getGameId() != null)
            req.queryString("gameId", filter.getGameId());
        if (filter.getMapId() != null)
            req.queryString("mapId", filter.getMapId());
        if (filter.getFlavorId() != null)
            req.queryString("flavorId", filter.getFlavorId());
        if (minLastUpdate != null)
            req.queryString("minLastUpdate", minLastUpdate);
        String body = req.asString().getBody();
        ServerInfo serverInfo = GSON.fromJson(body, ServerInfo.class);
        return serverInfo;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:Exorath,项目名称:ConnectorService,代码行数:20,代码来源:ConnectorServiceAPI.java

示例4: getJoinableServer

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
public Server getJoinableServer(Filter filter, String uuid){
    try {
        HttpRequest req = Unirest.get(url("/joinable/{uuid}"))
                .routeParam("uuid", uuid);
        if (filter.getGameId() != null)
            req.queryString("gameId", filter.getGameId());
        if (filter.getMapId() != null)
            req.queryString("mapId", filter.getMapId());
        if (filter.getFlavorId() != null)
            req.queryString("flavorId", filter.getFlavorId());
        String body = req.asString().getBody();
        Server server = GSON.fromJson(body, Server.class);
        return server;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
 
开发者ID:Exorath,项目名称:ConnectorService,代码行数:19,代码来源:ConnectorServiceAPI.java

示例5: get

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
public String get(String key) throws Exception {
    HttpRequest request = new HttpRequestWithBody(
        HttpMethod.GET,
        makeConsulUrl(key) + "?raw"
    ).getHttpRequest();

    authorizeHttpRequest(request);

    HttpResponse<String> response;

    try {
        response = HttpClientHelper.request(request, String.class);
    } catch (Exception exception) {
        throw new ConsulException("Consul request failed", exception);
    }

    if (response.getStatus() == 404) {
        return null;
    }

    String encrypted = response.getBody();

    return encryption.decrypt(encrypted);
}
 
开发者ID:jackprice,项目名称:gatekeeper,代码行数:25,代码来源:Client.java

示例6: 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

示例7: makeQuery

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
private String makeQuery(String query, boolean includeObsoletes) {
    HttpRequest req = formQueryRequest(query, includeObsoletes);
    HttpResponse<JsonNode> resp = null;

    String uri = null;

    try {
        resp = req.asJson();
    } catch (UnirestException e) {

        throw new RuntimeException(e);
    }

    if (resp.getStatus() == 200) {
        uri = findTermUri(resp.getBody());
    }
    logger.info("Found term URI {} for {}", uri, query);
    return uri;
}
 
开发者ID:EMBL-EBI-SUBS-OLD,项目名称:subs,代码行数:20,代码来源:OlsSearchServiceImpl.java

示例8: logAndSign

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
public void logAndSign(SignProvider signProvider, Map<String, Object> requestParams, HttpRequest httpRequest) {
    if (!log.isInfoEnabled()) return;

    signReq(signProvider, requestParams, httpRequest);
    this.start = System.currentTimeMillis();
    val methodName = httpRequest.getHttpMethod().name();
    val url = UrlDecodes.decodeQuietly(httpRequest.getUrl());
    val headers = buildHeaders(httpRequest.getHeaders());
    val contentTypes = httpRequest.getHeaders().get("Content-Type");
    val contentType = contentTypes != null && !contentTypes.isEmpty() ? contentTypes.get(0) : null;

    val body = getBodyAsString(requestParams, httpRequest);

    log.info("spring rest client {} {} request: {} {} headers:{} body: {}",
            syncOrAsync, uuid, methodName, url, headers, singleLine(contentType, body));
}
 
开发者ID:bingoohuang,项目名称:spring-rest-client,代码行数:17,代码来源:RestLog.java

示例9: createOriginalStringForSign

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
private String createOriginalStringForSign(Class<?> apiClass,
                                           Map<String, Object> requestParams,
                                           HttpRequest httpRequest) {
    val signStr = new StringBuilder();
    val logStr = new StringBuilder();
    val proxy = new AbbreviateAppendable(logStr, signStr);

    appendMethodAndUrl(httpRequest, proxy);
    appendHeaders(httpRequest, proxy);
    appendReqParams(requestParams, proxy);

    val log = LoggerFactory.getLogger(apiClass);
    log.debug("string to be signed : {}", logStr);

    return signStr.toString();
}
 
开发者ID:bingoohuang,项目名称:spring-rest-client,代码行数:17,代码来源:DefaultSignProvider.java

示例10: retriveFromStack

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
private String retriveFromStack(String question) throws UnirestException {
    HttpRequest request = Unirest.get(STACK_API_PATH)
            .queryString("q", "\"" + question + "\"")
            .queryString("site", "stackoverflow")
            .queryString("sort", "relevance");

    log.info("Asking for {}", question);
    HttpResponse<JsonNode> stackResponse = request.asJson();
    log.info("Stack response: {}", stackResponse.getBody().toString());

    JSONObject jsonLink = stackResponse.getBody().getObject().getJSONArray("items").getJSONObject(1);
    String response = jsonLink.getString("link").toString();
    log.info("Got answer {}", response);

    return response;
}
 
开发者ID:TouK,项目名称:janusz,代码行数:17,代码来源:StackOverflowCommand.java

示例11: tryGetWorkerID

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
/**
 * tries to get the workerID from the request.
 * Calls 'GET /get/:platform' from the Object-Service.
 * @param platform the current platform
 * @param queryParameter the passed query-Parameter
 * @return an completable future representing the request with the resulting location in the database
 */
public CompletableFuture<Optional<Integer>> tryGetWorkerID(String platform, ListMultimap<String, String> queryParameter) {
    String route = "/workers/" + platform + "/identity";
    logger.debug("Trying to get workerId for parameter {} with route {} from platform {}.", queryParameter, route, platform);
    return getRequest(route, builder -> {
        HttpRequest request = builder.getHttpRequest();
        for (Map.Entry<String, Collection<String>> entry : queryParameter.asMap().entrySet()) {
            request = request.queryString(entry.getKey(), entry.getValue());
        }
        return request;
    }).thenApply(response -> {
        if (response.getStatus() == 200) {
            logger.debug("Object service answered with status 200");
            return Optional.of(response.getBody().getObject().getInt("id"));
        } else if (response.getStatus() == 409) {
            logger.debug("Object service answered with status 409");
            return Optional.of(Integer.parseInt(response.getHeaders().getFirst("Location").replace(url+"/workers/", "")));
        } else if (response.getStatus() == 404){
            logger.debug("Object service answered with status 404");
            return Optional.empty();
        }
        return throwOr(response, Optional::empty);
    });
}
 
开发者ID:coolcrowd,项目名称:worker-service,代码行数:31,代码来源:Communication.java

示例12: 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

示例13: setAcceptHeader

import com.mashape.unirest.request.HttpRequest; //导入依赖的package包/类
private static HttpRequest setAcceptHeader(Method method, HttpRequest request) {
    if (isPrimitiveOrString(returnTypeof(method))) {
        request = request.header("accept", "text/plain");

    } else {
        request = request.header("accept", "application/json");

    }
    return request;
}
 
开发者ID:drinkwater-io,项目名称:drinkwater-java,代码行数:11,代码来源:Rest.java

示例14: 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

示例15: 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


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