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

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

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

HttpRequest.encode介绍

[英]Encode the given URL as an ASCII String

This method ensures the path and query segments of the URL are properly encoded such as ' ' characters being encoded to '%20' or any UTF-8 characters that are non-ASCII. No encoding of URLs is done by default by the HttpRequest constructors and so if URL encoding is needed this method should be called before calling the HttpRequest constructor.
[中]将给定URL编码为ASCII字符串
此方法确保URL的路径和查询段正确编码,例如将“”字符编码为“%20”或任何非ASCII的UTF-8字符。默认情况下,HttpRequest构造函数不进行URL编码,因此如果需要URL编码,则应在调用HttpRequest构造函数之前调用此方法。

代码示例

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

private static HttpsURLConnection createConnection(String url, String method, Boolean encode) {
    try {
      URL u = new URL(encode ? HttpRequest.encode(url) : url);
      HttpsURLConnection conn = (HttpsURLConnection) u.openConnection();
      conn.setRequestMethod(method);
      return conn;
    } catch (IOException e) {
      throw new HttpException(e);
    }
  }
}

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

private static HttpsURLConnection createConnection(String url, String method, Boolean encode) {
    try {
      URL u = new URL(encode ? HttpRequest.encode(url) : url);
      HttpsURLConnection conn = (HttpsURLConnection) u.openConnection();
      conn.setRequestMethod(method);
      return conn;
    } catch (IOException e) {
      throw new HttpsException(e);
    }
  }
}

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

private static HttpsURLConnection createConnection(String url, String method, Boolean encode) {
    try {
      URL u = new URL(encode ? HttpRequest.encode(url) : url);
      HttpsURLConnection conn = (HttpsURLConnection) u.openConnection();
      conn.setRequestMethod(method);
      return conn;
    } catch (IOException e) {
      throw new HttpsException(e);
    }
  }
}

代码示例来源: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 'PUT' 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 put(final CharSequence baseUrl,
               final Map<?, ?> params, final boolean encode) {
  String url = append(baseUrl, params);
  return put(encode ? encode(url) : url);
}

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

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

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

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

代码示例来源: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: 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: 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 head(final CharSequence baseUrl,
                final boolean encode, final Object... params) {
  String url = append(baseUrl, params);
  return head(encode ? encode(url) : url);
}

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

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

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

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

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

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

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

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

相关文章

HttpRequest类方法