com.github.kevinsawicki.http.HttpRequest.ok()方法的使用及代码示例

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

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

HttpRequest.ok介绍

[英]Is the response code a 200 OK?
[中]响应代码a 200可以吗?

代码示例

代码示例来源:origin: stackoverflow.com

HttpRequest request = HttpRequest.post("http://google.com");
request.part("status[body]", "Making a multipart request");
request.part("status[image]", new File("/home/kevin/Pictures/ide.png"));
if (request.ok())
 System.out.println("Status was updated");

代码示例来源:origin: stackoverflow.com

HttpRequest request = HttpRequest.post("http://google.com");
request.part("status[body]", "Making a multipart request");
request.part("status[image]", new File("/home/kevin/Pictures/ide.png"));
if (request.ok())
 System.out.println("Status was updated");

代码示例来源:origin: stackoverflow.com

HttpRequest request = HttpRequest.post("http://google.com");
request.part("status[body]", "Making a multipart request");//this is data
request.part("status[image]", new File("/home/kevin/Pictures/ide.png"));//this is your image
if (request.ok())
 System.out.println("Upload success");

代码示例来源:origin: stackoverflow.com

String httpQuery = new QueryBuilder().setLocalityFilter(query).build();

try {
      HttpRequest request =  HttpRequest.get(httpQuery);
      if (request.ok()) {
        String response = request.body();
        restaurantArrayList = JsonParser.parseHTTPResponse(response);
      }
      return restaurantArrayList;
  } catch (HttpRequest.HttpRequestException exception) {
      return null;
}

代码示例来源:origin: io.github.livingdocumentation/dot-diagram

@Override
public void render(String filename) throws InterruptedException, IOException {
  String dot = read(path + filename + ".dot");
  HttpRequest httpRequest = HttpRequest.get(GOOGLE_CHART_API, true, "cht", "gv", "chl", dot);
  if (httpRequest.ok()) {
    try (InputStream is = httpRequest.stream()) {
      Files.copy(is, Paths.get(path + filename + getImageExtension()));
    }
  } else {
    throw new DotDiagramException("Errors calling Graphviz chart.googleapis.com");
  }
}

代码示例来源:origin: org.codehaus.sonar/sonar-batch

@VisibleForTesting
void uploadMultiPartReport(File report) {
 LOG.debug("Publish results");
 long startTime = System.currentTimeMillis();
 URL url;
 try {
  url = new URL(serverClient.getURL() + "/api/computation/submit_report?projectKey=" + project.getEffectiveKey());
 } catch (MalformedURLException e) {
  throw new IllegalArgumentException("Invalid URL", e);
 }
 HttpRequest request = HttpRequest.post(url);
 request.trustAllCerts();
 request.trustAllHosts();
 request.header("User-Agent", String.format("SonarQube %s", server.getVersion()));
 request.basic(serverClient.getLogin(), serverClient.getPassword());
 request.part("report", null, "application/octet-stream", report);
 if (!request.ok()) {
  int responseCode = request.code();
  if (responseCode == 401) {
   throw new IllegalStateException(String.format(serverClient.getMessageWhenNotAuthorized(), CoreProperties.LOGIN, CoreProperties.PASSWORD));
  }
  if (responseCode == 403) {
   // SONAR-4397 Details are in response content
   throw new IllegalStateException(request.body());
  }
  throw new IllegalStateException(String.format("Fail to execute request [code=%s, url=%s]: %s", responseCode, url, request.body()));
 }
 long stopTime = System.currentTimeMillis();
 LOG.info("Analysis reports sent to server in " + (stopTime - startTime) + "ms");
}

代码示例来源:origin: ihaolin/antares

/**
   * download a file
   * @param url http url
   * @param output the output which downloaded content will fill into
   */
  public static void download(String url, OutputStream output){
    try {
      HttpRequest request =  HttpRequest.get(url);
      if (request.ok()){
        request.receive(output);
      } else {
        throw new HttpException("request isn't ok: " + request.body());
      }
    } catch (Exception e){
      throw new HttpException(e);
    }
  }
}

代码示例来源:origin: me.hao0/common

/**
   * download a file
   * @param url http url
   * @param output the output which downloaded content will fill into
   */
  public static void download(String url, OutputStream output){
    try {
      HttpRequest request =  HttpRequest.get(url);
      if (request.ok()){
        request.receive(output);
      } else {
        throw new HttpException("request isn't ok: " + request.body());
      }
    } catch (Exception e){
      throw new HttpException(e);
    }
  }
}

代码示例来源:origin: ihaolin/common

/**
   * download a file
   * @param url http url
   * @param output the output which downloaded content will fill into
   */
  public static void download(String url, OutputStream output){
    try {
      HttpRequest request =  HttpRequest.get(url);
      if (request.ok()){
        request.receive(output);
      } else {
        throw new HttpException("request isn't ok: " + request.body());
      }
    } catch (Exception e){
      throw new HttpException(e);
    }
  }
}

相关文章

微信公众号

最新文章

更多

HttpRequest类方法