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

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

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

HttpRequest.post介绍

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

代码示例

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

/**
 * This method sends a request to attach an observer to a specific metric
 * @param callback the address on which the observer is running
 *
 * @param metric the requested metric
 */
public void attachObserver(String callback, String metric) {
  String url = address + "/" + version + "/metrics/" + metric + "/observers";
  try {
  HttpRequest.post(url).send(callback).code();
      journal.log(Level.INFO, "Observer attached");
  } catch (Exception e) {
    journal.log(Level.INFO, "Connection to the monitoring manager refused");
  }
}

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

public static boolean subscribe(String email, String description, String location, boolean fullTime) {
  HashMap<String, String> parameters = new HashMap<String, String>();
  parameters.put(SUBSCRIPTION_EMAIL_PARAM, email);
  parameters.put(SUBSCRIPTION_DESCRIPTION_PARAM, description);
  parameters.put(SUBSCRIPTION_LOCATION_PARAM, location);
  parameters.put(SUBSCRIPTION_FULL_TIME_PARAM, String.valueOf(fullTime));
  String response = HttpRequest.post(ApiConstants.EMAIL_SUBSCRIPTION_URL)
      .part(SUBSCRIPTION_EMAIL_PARAM, email)
      .part(SUBSCRIPTION_DESCRIPTION_PARAM, description)
      .part(SUBSCRIPTION_LOCATION_PARAM, location)
      .part(SUBSCRIPTION_FULL_TIME_PARAM, String.valueOf(fullTime))
      .body();
  return SUBSCRIPTION_OK_PARAM.equals(response);
}

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

/**
 * This method sends a request to upload a monitoring rule to the monitoring manager.
 @param rule is the monitoring rule to be uploaded
 @return the response of the monitoring manager
 */
public String addMonitoringRule(String rule){
  String url = address + "/" + version + "/monitoring-rules";
  String response = null;
  try {
    response = HttpRequest.post(url).send(rule).body();
  } catch (Exception e) {
    journal.log(Level.INFO, "Connection to the monitoring manager refused");
  }
  return response;
}

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

/**
 * Share the stats to share URL. Must not be called if sharing is disabled.
 * shareEnabled check is not done to avoid double checking.
 */
private void shareStats() {
  try {
    int code = HttpRequest.post(shareURL)
        .connectTimeout(5000)
        .readTimeout(5000)
        .send(objectMapper.writer().writeValueAsString(stats).getBytes(Charsets.UTF_8))
        .code();
    if (code >= 400) {
      logger.info("sharing stats on {} failed. Response code: {}", shareURL, code);
    }
  } catch (Exception e) {
    logger.info("sharing stats on {} failed. Exception: {}", shareURL, e.getMessage());
  }
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
                final Map<?, ?> params, final boolean encode) {
  String url = append(baseUrl, params);
  return post(encode ? encode(url) : url);
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
                final boolean encode, final Object... params) {
  String url = append(baseUrl, params);
  return post(encode ? encode(url) : url);
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
  final Map<?, ?> params, final boolean encode) {
 String url = append(baseUrl, params);
 return post(encode ? encode(url) : url);
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
  final boolean encode, final Object... params) {
 String url = append(baseUrl, params);
 return post(encode ? encode(url) : url);
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
                final boolean encode, final Object... params) {
  String url = append(baseUrl, params);
  return post(encode ? encode(url) : url);
}

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

public String getToken(String code) throws JsonProcessingException, IOException {
  String body = HttpRequest.post(ACCESS_TOKEN_URL,
      ImmutableMap.of(
          "client_id", config.getGithubClientId(),
          "client_secret", config.getGithubClientSecret(),
          "code", code
          ),
      false).header("Accept", "application/json").body();
  JsonNode node = om.readTree(body);
  if (node.has("access_token")) {
    String token = node.get("access_token").asText();
    return token;
  } else {
    throw new AppException(Error.AUTH2_CODE_ERROR, body);
  }
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
  final Map<?, ?> params, final boolean encode) {
 String url = append(baseUrl, params);
 return post(encode ? encode(url) : url);
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
                final Map<?, ?> params, final boolean encode) {
  String url = append(baseUrl, params);
  return post(encode ? encode(url) : url);
}

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

/**
 * Start a 'POST' 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 post(final CharSequence baseUrl,
  final boolean encode, final Object... params) {
 String url = append(baseUrl, params);
 return post(encode ? encode(url) : url);
}

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

/**
 * upload file
 * @param url url
 * @param fieldName field name
 * @param fileName file name
 * @param in InputStream
 * @param params other params
 * @return string response
 */
public static String upload(String url, String fieldName, String fileName, InputStream in, Map<String, String> params){
  try {
    HttpRequest request = HttpRequest.post(url);
    if (!params.isEmpty()){
      for (Map.Entry<String, String> param : params.entrySet()){
        request.part(param.getKey(), param.getValue());
      }
    }
    request.part(fieldName , fileName, null, in);
    return request.body();
  } catch (Exception e){
    throw new HttpException(e);
  }
}

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

/**
 * upload file
 * @param url url
 * @param fieldName field name
 * @param fileName file name
 * @param in InputStream
 * @param params other params
 * @return string response
 */
public static String upload(String url, String fieldName, String fileName, InputStream in, Map<String, String> params){
  try {
    HttpRequest request = HttpRequest.post(url);
    if (!params.isEmpty()){
      for (Map.Entry<String, String> param : params.entrySet()){
        request.part(param.getKey(), param.getValue());
      }
    }
    request.part(fieldName , fileName, null, in);
    return request.body();
  } catch (Exception e){
    throw new HttpException(e);
  }
}

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

/**
 * This method sends an update to the monitoring manager about the state of the deployment
 *
 * @param update the state of the deployment
 */
public void addInstances(Model update){
  String url = address + "/" + version + "/model/resources";
  int result;
  Gson gson = new GsonBuilder().serializeNulls().create();
  String json = gson.toJson(update);
  try {
    journal.log(Level.INFO, ">> Connecting to the monitoring platform at "+address+"...");
    printComponentname(update);
    result = HttpRequest.post(url).send(json).code();
  } catch (Exception e) {
  result = 0;
  }
  printResult(result);
}

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

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

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

private String doPost() {
  HttpRequest post = HttpRequest.post(url, params, encode)
      .headers(headers)
      .connectTimeout(connectTimeout)
      .readTimeout(readTimeout)
      .acceptGzipEncoding()
      .uncompress(true);
  setOptionalHeaders(post);
  if (!Strings.isNullOrEmpty(body)){
    post.send(body);
  }
  if (ssl){
    trustHttps(post);
  }
  return post.body();
}

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

private String doPost() {
  HttpRequest post = HttpRequest.post(url, params, encode)
      .headers(headers)
      .connectTimeout(connectTimeout)
      .readTimeout(readTimeout)
      .acceptGzipEncoding()
      .uncompress(true);
  setOptionalHeaders(post);
  if (!Strings.isNullOrEmpty(body)){
    post.send(body);
  }
  if (ssl){
    trustHttps(post);
  }
  return post.body();
}

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

private String doPost() {
  HttpRequest post = HttpRequest.post(url, params, encode)
      .headers(headers)
      .connectTimeout(connectTimeout)
      .readTimeout(readTimeout)
      .acceptGzipEncoding()
      .uncompress(true);
  setOptionalHeaders(post);
  if (!Strings.isNullOrEmpty(body)){
    post.send(body);
  }
  if (ssl){
    trustHttps(post);
  }
  return post.body();
}

相关文章

HttpRequest类方法