com.mashape.unirest.request.HttpRequest类的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(10.2k)|赞(0)|评价(0)|浏览(122)

本文整理了Java中com.mashape.unirest.request.HttpRequest类的一些代码示例,展示了HttpRequest类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest类的具体详情如下:
包路径:com.mashape.unirest.request.HttpRequest
类名称:HttpRequest

HttpRequest介绍

暂无

代码示例

代码示例来源:origin: Kong/unirest-java

public HttpRequest queryString(String name, Collection<?> value) {
  for (Object cur : value) {
    queryString(name, cur);
  }
  return this;
}

代码示例来源:origin: Kong/unirest-java

Set<Entry<String, String>> entrySet = ((Map<String, String>) defaultHeaders).entrySet();
  for (Entry<String, String> entry : entrySet) {
    request.header(entry.getKey(), entry.getValue());
if (!request.getHeaders().containsKey(USER_AGENT_HEADER)) {
  request.header(USER_AGENT_HEADER, USER_AGENT);
if (!request.getHeaders().containsKey(ACCEPT_ENCODING_HEADER)) {
  request.header(ACCEPT_ENCODING_HEADER, "gzip");
  URL url = new URL(request.getUrl());
  URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), URLDecoder.decode(url.getPath(), "UTF-8"), "", url.getRef());
  urlToRequest = uri.toURL().toString();
switch (request.getHttpMethod()) {
case GET:
  reqObj = new HttpGet(urlToRequest);
Set<Entry<String, List<String>>> entrySet = request.getHeaders().entrySet();
for (Entry<String, List<String>> entry : entrySet) {
  List<String> values = entry.getValue();
if (!(request.getHttpMethod() == HttpMethod.GET || request.getHttpMethod() == HttpMethod.HEAD)) {
  if (request.getBody() != null) {
    HttpEntity entity = request.getBody().getEntity();
    if (async) {
      if (reqObj.getHeaders(CONTENT_TYPE) == null || reqObj.getHeaders(CONTENT_TYPE).length == 0) {

代码示例来源:origin: lets-blade/blade

protected String bodyToString(String path) throws Exception {
  return get(path).asString().getBody();
}

代码示例来源:origin: gradle.plugin.GoBqa/gradle-plugin

HttpRequest getRequestNoBody;
getRequestNoBody = Unirest.get(url);
getRequestNoBody = (contentType != null) ? getRequestNoBody.header("content-type", contentType) : getRequestNoBody;
getRequestNoBody = (basicAuth != null) ? getRequestNoBody.basicAuth(basicAuth.username, basicAuth.password) : getRequestNoBody;
Enumeration<?> e = headers.propertyNames();
while (e.hasMoreElements()) {
  String value = headers.getProperty(headName);
  getRequestNoBody = getRequestNoBody.header(headName, value);
  String value = query.getProperty(queryName);
  getRequestNoBody = getRequestNoBody.queryString(queryName, value);
  response = getRequestNoBody.asString();
}catch (Exception ex){
  track.fail("Getrequest:Error during call Api Rest op from URL::"+getRequestNoBody.getUrl() +"' \n" + ex.getMessage());

代码示例来源:origin: forcelate/forcelate-benchmarks

@Override
  public void trades() throws IOException, UnirestException {
    HttpResponse<String> response = Unirest.get(POLONIEX_BASE_URL)
        .queryString(COMMAND_QUERY_KEY, "returnTradeHistory")
        .queryString("currencyPair", "BTC_NXT")
        .queryString("start", "1410158341")
        .queryString("end", "1410158341")
        .asString();
    unirestParamsClient.trades(response, POLONIEX);
  }
}

代码示例来源:origin: CognitiveJ/cognitivej

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);
  }
}

代码示例来源:origin: Kong/unirest-java

@Override
public HttpRequestWithBody header(String name, String value) {
  return (HttpRequestWithBody) super.header(name, value);
}

代码示例来源:origin: DiUS/pact-workshop-jvm

private Optional<JsonNode> loadProviderJson(String dateTime) throws UnirestException {
 HttpRequest getRequest = Unirest.get(url + "/provider.json");
 if (StringUtils.isNoneEmpty(dateTime)) {
  getRequest = getRequest.queryString("validDate", dateTime);
 }
 HttpResponse<JsonNode> jsonNodeHttpResponse = getRequest.asJson();
 if (jsonNodeHttpResponse.getStatus() == 200) {
  return Optional.of(jsonNodeHttpResponse.getBody());
 } else {
  return Optional.empty();
 }
}

代码示例来源:origin: vulnersCom/burp-vulners-scanner

.routeParam("path", "software")
    .queryString("software", software.getAlias())
    .queryString("version", software.getVersion())
    .queryString("type", software.getMatchType());
callbacks.printOutput("[Vulners] start check for domain " + domainName + " for software " + software.getName() + "/" + software.getVersion() + " : " + request.getUrl());
request.asJsonAsync(new VulnersRestCallback(callbacks) {

代码示例来源:origin: biezhi/java-library-examples

public static void main(String[] args) throws UnirestException {
    HttpResponse<JsonNode> response = Unirest.get("http://httpbin.org/{method}")
        .routeParam("method", "get")
        .queryString("name", "biezhi")
        .asJson();

    System.out.println(response.getBody().toString());
  }
}

代码示例来源:origin: com.github.bingoohuang/blackcat-instrument

public static void prepareRPC(HttpRequest httpRequest) {
  val context = threadLocal.get();
  if (context == null) return;
  val httpMethod = httpRequest.getHttpMethod().name();
  trace("RPC", httpMethod + ":" + httpRequest.getUrl());
  httpRequest.header(BLACKCAT_TRACEID, context.getTraceId());
  val linkId = context.getParentLinkId() + String.format(".%06d", context.getSubLinkId());
  httpRequest.header(BLACKCAT_LINKID, linkId);
}

代码示例来源:origin: net.dv8tion/JDA

private JSONObject toObject(BaseRequest request)
{
  try
  {
    if (api.isDebug())
    {
      System.out.printf("Requesting %s -> %s\n\tPayload: %s\n\tResponse: ", request.getHttpRequest().getHttpMethod().name(), request.getHttpRequest().getUrl(), ((request instanceof RequestBodyEntity)? ((RequestBodyEntity) request).getBody().toString():"None"));
    }
    String body = request.asString().getBody();
    if (api.isDebug())
    {
      System.out.println(body);
    }
    return body == null ? null : new JSONObject(body);
  }
  catch (UnirestException e)
  {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: kevoree/kevoree

default HttpResponse<RDeployUnit[]> getLatestsDus(String namespace, String tdefName, long tdefVersion)
    throws UnirestException {
  return Unirest.get(this.baseUrl() + "/api/namespaces/{namespace}/tdefs/{tdefName}/{tdefVersion}/dus")
      .routeParam("namespace", namespace)
      .routeParam("tdefName", tdefName)
      .routeParam("tdefVersion", String.valueOf(tdefVersion))
      .queryString("version", "latest")
      .asObject(RDeployUnit[].class);
}

代码示例来源:origin: com.infotel.seleniumRobot/core

@Override
public File stopVideoCapture(String outputFile) {
  if (nodeUrl == null) {
    throw new ScenarioException("You cannot stop video capture before driver has been created and corresponding node instanciated");
  }
  
  logger.info("stopping capture");
  try {
    HttpResponse<InputStream> videoResponse = Unirest.get(String.format("%s%s", nodeUrl, NODE_TASK_SERVLET))
      .queryString("action", "stopVideoCapture")
      .queryString("session", sessionId).asBinary();
    InputStream videoI = videoResponse.getBody();
    
    File videoFile = new File(outputFile);
    FileOutputStream os = new FileOutputStream(videoFile);
    IOUtils.copy(videoI, os);
    os.close();
    
    return videoFile;
    
  } catch (UnirestException | IOException e) {
    logger.warn(String.format("Could not stop video capture: %s", e.getMessage()));
    return null;
  }
}

代码示例来源:origin: com.infotel.seleniumRobot/core

protected JSONArray getJSonArray(BaseRequest request) throws UnirestException {
  HttpResponse<String> response = request.asString();
  
  if (response.getStatus() == 423) {
    String error = new JSONObject(response.getBody()).getString("detail");
    throw new SeleniumRobotServerException(error);
  }
  
  if (response.getStatus() >= 400) {
    try {
      String error = new JSONObject(response.getBody()).getString("detail");
      throw new SeleniumRobotServerException(String.format("request to %s failed: %s", request.getHttpRequest().getUrl(), error));
    } catch (Exception e) {
      throw new UnirestException(String.format("request to %s failed: %s", request.getHttpRequest().getUrl(), response.getStatusText()));
    }
    
  }
  
  if (response.getStatus() == 204) {
    return new JSONArray();
  }
  
  return new JSONArray(response.getBody());
}

代码示例来源:origin: Kong/unirest-java

@Override
  public GetRequest basicAuth(String username, String password) {
    super.basicAuth(username, password);
    return this;
  }
}

代码示例来源:origin: hatboysam/JavaSnap

private static HttpResponse<InputStream> requestStoryBinary(String path) throws UnirestException {
  HttpRequest req = Unirest.get(BASE_URL + path)
      .header(JSON_TYPE_KEY, JSON_TYPE)
      .header(USER_AGENT_KEY, USER_AGENT);
  // Execute and return as bytes
  HttpResponse<InputStream> resp = req.asBinary();
  // Record
  lastRequestPath = path;
  lastResponse = resp;
  lastResponseBodyClass = InputStream.class;
  return resp;
}

代码示例来源:origin: gradle.plugin.GoBqa/gradle-plugin

postRequestNoBody = (contentType != null) ? postRequestNoBody.header("content-type", contentType) : postRequestNoBody;
postRequestNoBody = (basicAuth != null) ? postRequestNoBody.basicAuth(basicAuth.username, basicAuth.password) : postRequestNoBody;
  String headName = (String) e.nextElement();
  String value = headers.getProperty(headName);
  postRequestNoBody = postRequestNoBody.header(headName, value);
  String queryName = (String) e.nextElement();
  String value = query.getProperty(queryName);
  postRequestNoBody = postRequestNoBody.queryString(queryName, value);
  response = postRequestNoBody.asString();
} catch (Exception ex) {
  track.fail("Postrequest:Error during call Api Rest op from URL::" + postRequestNoBody.getUrl() + "' \n" + ex.getMessage());

代码示例来源:origin: forcelate/forcelate-benchmarks

@Override
public void orderBook() throws IOException, UnirestException {
  HttpResponse<String> response = Unirest.get(POLONIEX_BASE_URL)
      .queryString(COMMAND_QUERY_KEY, "returnOrderBook")
      .queryString("currencyPair", "all")
      .queryString("depth", "100")
      .asString();
  unirestParamsClient.orderBook(response, POLONIEX);
}

代码示例来源:origin: Kong/unirest-java

@Override
public GetRequest header(String name, String value) {
  return (GetRequest) super.header(name, value);
}

相关文章