rename FormMap to ArgMap then support url arg
This commit is contained in:
40
src/main/java/com/imyeyu/network/ArgMap.java
Normal file
40
src/main/java/com/imyeyu/network/ArgMap.java
Normal file
@@ -0,0 +1,40 @@
|
||||
package com.imyeyu.network;
|
||||
|
||||
import com.imyeyu.utils.Encoder;
|
||||
import org.apache.hc.client5.http.fluent.Form;
|
||||
import org.apache.hc.core5.http.NameValuePair;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* HashMap 构建 {@link org.apache.hc.client5.http.fluent.Form} 参数列表
|
||||
*
|
||||
* @author 夜雨
|
||||
* @since 2025-06-26 15:41
|
||||
*/
|
||||
public class ArgMap<K, V> extends HashMap<K, V> {
|
||||
|
||||
public List<NameValuePair> toNameValuePair() {
|
||||
Form form = Form.form();
|
||||
for (Map.Entry<K, V> item : entrySet()) {
|
||||
form.add(item.getKey().toString(), item.getValue().toString());
|
||||
}
|
||||
return form.build();
|
||||
}
|
||||
|
||||
public String toURL() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (Map.Entry<K, V> item : entrySet()) {
|
||||
sb.append(item.getKey().toString()).append('=').append(Encoder.urlArg(item.getValue().toString()));
|
||||
sb.append('&');
|
||||
}
|
||||
sb.deleteCharAt(sb.length() - 1);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public String toURL(String url) {
|
||||
return url + "?" + toURL();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user