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

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

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

HttpRequest.get介绍

[英]Start a 'GET' request to the given URL
[中]启动对给定URL的“GET”请求

代码示例

代码示例来源:origin: BoD/jraf-android-util

public static HttpRequest post(String url) throws IOException {
    HttpRequest res = HttpRequest.get(url);
    setDefaultOptions(res);
    return res;
  }
}

代码示例来源:origin: BoD/jraf-android-util

public static HttpRequest get(String url) throws IOException {
  HttpRequest res = HttpRequest.get(url);
  setDefaultOptions(res);
  return res;
}

代码示例来源:origin: com.codeslap/github-jobs-java-api

public User getUser(String username) {
    String url = String.format(ApiConstants.API_URL, String.format(ApiConstants.GET_USER, username));
    try {
      String response = HttpRequest.get(url).body();
      // convert json to object
      Gson gson = new Gson();
      return gson.fromJson(response, User.class);
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
}

代码示例来源:origin: SINTEF-9012/cloudml

/**
 * This methods sends a request to get all the metrics available
 *
 * @return a list of metrics
 */
public List<String> getMetrics(){
  String url = address + "/" + version + "/metrics";
  try {
    String response = HttpRequest.get(url).body();
  } catch (Exception e) {
    journal.log(Level.INFO, "Connection to the monitoring manager refused");
    return null;
  }
  //TODO parse results
  return null;
}

代码示例来源:origin: k55k32/cms-admin-end

public static String getLocation(String ip) throws JsonProcessingException, IOException {
    String result = HttpRequest.get(api, ImmutableMap.of("ip", ip, "datatype", "jsonp", "token", token), false).body();
    ObjectMapper om = new ObjectMapper();
    JsonNode node = om.readTree(result);
    ArrayNode data = (ArrayNode) node.get("data");
    return data.get(0).asText() + data.get(1).asText() + data.get(2).asText() + data.get(3).asText();
  }
}

代码示例来源:origin: com.codeslap/github-jobs-java-api

public static Job getJob(String id, boolean markdown) {
  String baseUrl = String.format(ApiConstants.JOB_URL, id);
  ArrayList<NameValuePair> pairs = new ArrayList<NameValuePair>();
  if (markdown) {
    pairs.add(new NameValuePair(ApiConstants.MARKDOWN, String.valueOf(markdown)));
  }
  try {
    String url = createUrl(baseUrl, pairs);
    String response = HttpRequest.get(url).body();
    // convert json to object
    Gson gson = new Gson();
    return gson.fromJson(response, Job.class);
  } catch (URIException e) {
    e.printStackTrace();
  }
  return null;
}

代码示例来源:origin: lkorth/httpebble-android

/**
 * Start a 'GET' request to the given URL along with the query params
 *
 * @param baseUrl
 * @param params  The query parameters to include as part of the baseUrl
 * @param encode  true to encode the full URL
 * @return request
 * @see #append(CharSequence, Map)
 * @see #encode(CharSequence)
 */
public static HttpRequest get(final CharSequence baseUrl,
               final Map<?, ?> params, final boolean encode) {
  String url = append(baseUrl, params);
  return get(encode ? encode(url) : url);
}

代码示例来源:origin: com.github.kevinsawicki/http-request

/**
 * Start a 'GET' request to the given URL along with the query params
 *
 * @param baseUrl
 * @param params
 *          The query parameters to include as part of the baseUrl
 * @param encode
 *          true to encode the full URL
 *
 * @see #append(CharSequence, Map)
 * @see #encode(CharSequence)
 *
 * @return request
 */
public static HttpRequest get(final CharSequence baseUrl,
  final Map<?, ?> params, final boolean encode) {
 String url = append(baseUrl, params);
 return get(encode ? encode(url) : url);
}

代码示例来源:origin: lkorth/httpebble-android

/**
 * Start a 'GET' request to the given URL along with the query params
 *
 * @param baseUrl
 * @param encode  true to encode the full URL
 * @param params  the name/value query parameter pairs to include as part of the
 *                baseUrl
 * @return request
 * @see #append(CharSequence, String...)
 * @see #encode(CharSequence)
 */
public static HttpRequest get(final CharSequence baseUrl,
               final boolean encode, final Object... params) {
  String url = append(baseUrl, params);
  return get(encode ? encode(url) : url);
}

代码示例来源:origin: tcking/GiraffePlayer2

/**
 * Start a 'GET' request to the given URL along with the query params
 *
 * @param baseUrl
 * @param encode
 *          true to encode the full URL
 * @param params
 *          the name/value query parameter pairs to include as part of the
 *          baseUrl
 *
 * @see #append(CharSequence, Object...)
 * @see #encode(CharSequence)
 *
 * @return request
 */
public static HttpRequest get(final CharSequence baseUrl,
               final boolean encode, final Object... params) {
  String url = append(baseUrl, params);
  return get(encode ? encode(url) : url);
}

代码示例来源:origin: com.restfuse/com.eclipsesource.restfuse

/**
 * Start a 'GET' request to the given URL along with the query params
 *
 * @param baseUrl
 * @param encode
 *          true to encode the full URL
 * @param params
 *          the name/value query parameter pairs to include as part of the
 *          baseUrl
 *
 * @see #append(CharSequence, String...)
 * @see #encode(CharSequence)
 *
 * @return request
 */
public static HttpRequest get(final CharSequence baseUrl,
  final boolean encode, final Object... params) {
 String url = append(baseUrl, params);
 return get(encode ? encode(url) : url);
}

代码示例来源:origin: k55k32/cms-admin-end

public Guest getGuest(String code) throws JsonProcessingException, IOException {
    String token = getToken(code);
    String body = HttpRequest.get(USER_URL, ImmutableMap.of("access_token", token), true).body();
    JsonNode jsonNode = om.readTree(body);
    String email = jsonNode.get("email").asText(null);
    String nickname = jsonNode.get("login").asText(null);
    String avatar = jsonNode.get("avatar_url").asText(null);
    Guest guest = new Guest();
    guest.setEmail(email);
    guest.setNickname(nickname);
    guest.setAvatar(avatar);
    guest.setThirdData(body);
    return guest;

  }
}

代码示例来源: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: com.restfuse/com.eclipsesource.restfuse

public Response get() {
 HttpRequest request = HttpRequest.get( url );
 addContentType( request );
 addHeaders( request );
 addAuthentication( request );
 sendRequest( request );
 return new ResponseImpl( request );
}

代码示例来源: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);
    }
  }
}

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

private String doGet() {
  HttpRequest get = HttpRequest.get(url, params, encode)
      .headers(headers)
      .connectTimeout(connectTimeout)
      .readTimeout(readTimeout)
      .acceptGzipEncoding()
      .uncompress(true);
  if (ssl){
    trustHttps(get);
  }
  setOptionalHeaders(get);
  return get.body();
}

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

private String doGet() {
  HttpRequest get = HttpRequest.get(url, params, encode)
      .headers(headers)
      .connectTimeout(connectTimeout)
      .readTimeout(readTimeout)
      .acceptGzipEncoding()
      .uncompress(true);
  if (ssl){
    trustHttps(get);
  }
  setOptionalHeaders(get);
  return get.body();
}

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

private String doGet() {
  HttpRequest get = HttpRequest.get(url, params, encode)
      .headers(headers)
      .connectTimeout(connectTimeout)
      .readTimeout(readTimeout)
      .acceptGzipEncoding()
      .uncompress(true);
  if (ssl){
    trustHttps(get);
  }
  setOptionalHeaders(get);
  return get.body();
}

相关文章

HttpRequest类方法