com.mashape.unirest.http.HttpResponse.getStatus()方法的使用及代码示例

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

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

HttpResponse.getStatus介绍

暂无

代码示例

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

@Test
public void testListen() throws Exception {
  Blade blade = Blade.of();
  blade.listen(9001).start().await();
  try {
    int code = Unirest.get("http://127.0.0.1:9001").asString().getStatus();
    assertEquals(404, code);
  } finally {
    blade.stop();
    try {
      new Socket("127.0.0.1", 9001);
      Assert.fail("Server is still running");
    } catch (ConnectException e) {
    }
  }
}

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

private void auth(KevoreeRegistryClient client) throws MojoExecutionException, UnirestException, KevoreeRegistryException {
    HttpResponse<RAuth> authRes = client.auth(login, password);
    if (authRes.getStatus() == 401) {
      throw new MojoExecutionException("You are not logged in");
    } else {
      throw  new MojoExecutionException("Something went wrong while authenticating " + login + " (status: " + authRes.getStatusText()+")");
    }
  }
}

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

@Test
public void testListenAddress() throws Exception {
  Blade blade = Blade.of();
  blade.listen("localhost", 9002).start().await();
  try {
    int code = Unirest.get("http://localhost:9002/").asString().getStatus();
    assertEquals(404, code);
  } finally {
    blade.stop();
  }
}

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

private void checkForError(HttpResponse response) {
  if (response.getStatus() == HttpStatus.SC_ACCEPTED || response.getStatus() == HttpStatus.SC_OK)
    return;
  ErrorHandler errorHandler = errorHandlers.getOrDefault(response.getStatus(), new ErrorHandler());
  errorHandler.publishError(response);
}

代码示例来源:origin: IQSS/dataverse

static UploadRequestResponse makeUploadRequest(HttpResponse<String> uploadRequest) {
  int status = uploadRequest.getStatus();
  String body = uploadRequest.getBody();
  logger.fine("Got " + status + " with body: " + body);
  return new UploadRequestResponse(uploadRequest.getStatus(), body);
}

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

protected String extractErrorString(@NotNull HttpResponse httpResponse) {
    return String.format("Status:%d; Body: %s", httpResponse.getStatus(), httpResponse.getBody());
  }
}

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

@Override
public void completed(HttpResponse<JsonNode> response) {
  int      code = response.getStatus();
  JsonNode body = response.getBody();
  System.out.println("Status Code: " + code);
  System.out.println(body.toString());
}

代码示例来源:origin: shizuchengxuyuan/net.sz.java

@Override
public void completed(HttpResponse<String> response) {
  int code = response.getStatus();
  // Map<String, String> headers = response.getHeaders();
  String body = response.getBody();
  //  InputStream rawBody = response.getRawBody();.
  log.info("body:" + body);
}

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

protected boolean isAlive(String testUrl) {
  try {
    return Unirest.get(url + testUrl).asString().getStatus() == 200;
  } catch (UnirestException e) {
    return false;
  } 
}

代码示例来源:origin: thejamesthomas/javabank

public int deleteAllImposters() {
  try {
    HttpResponse<JsonNode> response = Unirest.delete(baseUrl + "/imposters").asJson();
    return response.getStatus();
  } catch (UnirestException e) {
    return 500;
  }
}

代码示例来源:origin: thejamesthomas/javabank

public boolean isMountebankRunning() {
  try {
    HttpResponse<JsonNode> response = Unirest.get(baseUrl).asJson();
    return response.getStatus() == 200;
  } catch (UnirestException e) {
    return false;
  }
}

代码示例来源:origin: thejamesthomas/javabank

public int createImposter(Imposter imposter) {
  try {
    HttpResponse<JsonNode> response = Unirest.post(baseUrl + "/imposters").body(imposter.toString()).asJson();
    return response.getStatus();
  } catch (UnirestException e) {
    return 500;
  }
}

代码示例来源:origin: cz.etnetera/reesmo-writer

protected void request(String url) throws StorageException {
  HttpResponse<String> response;
  try {
    response = Unirest.get(url).basicAuth(username, password).asString();
  } catch (UnirestException e) {
    throw new StorageException("Unable to execute request on url " + url, e);
  }
  if (response.getStatus() != 200) {
    throw new StorageException("Wrong status code " + response.getStatus() + " when requesting url " + url);
  }
}

代码示例来源: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: lt.tokenmill.crawling/page-analyzer

public static HtmlAnalysisResult analyze(Map<String, String> config, String url) {
  try {
    String userAgent = config.getOrDefault(CONFIG_USER_AGENT, DEFAULT_USER_AGENT);
    HttpResponse<String> response = Unirest.get(url)
        .header("User-Agent", userAgent)
        .asString();
    return analyze(config, url, response.getBody(), response.getStatus(), response.getHeaders());
  } catch (UnirestException e) {
    throw new RuntimeException(e);
  }
}

代码示例来源:origin: streampipes/streampipes-ce

private static int registerServiceHttpClient(String body) throws UnirestException {
  HttpResponse<JsonNode> jsonResponse = Unirest.put(consulURL().toString() + "/" + CONSUL_URL_REGISTER_SERVICE)
      .header("accept", "application/json")
      .body(body)
      .asJson();
  return jsonResponse.getStatus();
}

代码示例来源:origin: thejamesthomas/javabank

@Test
public void shouldVerifyMountebankIsRunning() throws UnirestException {
  when(Unirest.get(Client.DEFAULT_BASE_URL)).thenReturn(getRequest);
  when(getRequest.asJson()).thenReturn(httpResponse);
  when(httpResponse.getStatus()).thenReturn(Integer.valueOf(200));
  assertThat(client.isMountebankRunning()).isEqualTo(true);
}

代码示例来源:origin: mattia-battiston/clean-architecture-example

private void whenTheCapacityIsRetrievedForExchange(String exchangeCode) throws UnirestException {
  String apiPath = GetCapacityForExchangeEndpoint.API_PATH.replace("{exchangeCode}", exchangeCode);
  String apiUrl = "http://localhost:8080" + apiPath;
  log("API Url", apiUrl);
  HttpResponse<String> httpResponse = Unirest.get(apiUrl).asString();
  responseStatus = httpResponse.getStatus();
  log("Response Status", responseStatus);
  responseContent = httpResponse.getBody();
  log("Response Content", formatJson(responseContent));
}

代码示例来源:origin: mattia-battiston/clean-architecture-example

private void whenTheApiToGetTheDeviceDetailsIsCalledForThatDevice() throws UnirestException {
  String apiPath = GetBroadbandAccessDeviceEndpoint.API_PATH.replace("{hostname}", HOSTNAME);
  String apiUrl = "http://localhost:8080" + apiPath;
  log("API Url", apiUrl);
  HttpResponse<String> httpResponse = Unirest.get(apiUrl).asString();
  responseStatus = httpResponse.getStatus();
  log("Response Status", responseStatus);
  responseContent = httpResponse.getBody();
  log("Response Content", formatJson(responseContent));
}

代码示例来源:origin: mesos/elasticsearch

@Test
public void shouldStartAndServeFile() throws UnknownHostException, UnirestException, InterruptedException {
  final SimpleFileServer simpleFileServer = new SimpleFileServer(TEST_FILE);
  simpleFileServer.run();
  InetSocketAddress address = simpleFileServer.getAddress();
  String serverAddress = NetworkUtils.addressToString(address, true);
  HttpResponse<String> response = Unirest.get(serverAddress + "/get").asString();
  assertEquals(200, response.getStatus());
  assertTrue(response.getBody().contains("This is a test file"));
}

相关文章