
top.zeimao77.product.http.HttpCurlCmdUtil Maven / Gradle / Ivy
package top.zeimao77.product.http;
import java.util.Map;
public class HttpCurlCmdUtil implements IHttpClient{
public static final HttpCurlCmdUtil INSTANCE = new HttpCurlCmdUtil();
@Override
public String sendPost(String url, String body, Map headers, int timeout) {
StringBuilder cmdBuiler = new StringBuilder("curl -X POST");
if(headers != null && !headers.isEmpty()) {
for (String s : headers.keySet())
cmdBuiler.append(" --header '").append(s).append(": ").append(headers.get(s)).append("'");
}
if(body != null)
cmdBuiler.append(" --data '").append(body).append("'");
if(url != null)
cmdBuiler.append(" '").append(url).append("'");
return cmdBuiler.toString();
}
@Override
public String sendGet(String url, Map headers, int timeout) {
StringBuilder cmdBuiler = new StringBuilder("curl ");
if(headers != null && !headers.isEmpty()) {
for (String s : headers.keySet())
cmdBuiler.append(" --header '").append(s).append(": ").append(headers.get(s)).append("'");
}
if(url != null)
cmdBuiler.append(" '").append(url).append("'");
return cmdBuiler.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy