com.founder.core.utils.HttpUtils Maven / Gradle / Ivy
package com.founder.core.utils;
import com.founder.core.httpclient.HttpClient;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Map;
import java.util.Set;
/**
* @author zhunian
* @create 2018-01-22 11:34
**/
public class HttpUtils {
public static String genUrlParams(Map paraMap) {
if(paraMap == null || paraMap.isEmpty()) return "";
StringBuffer urlParam = new StringBuffer();
Set keySet = paraMap.keySet();
int i = 0;
for(String key:keySet) {
urlParam.append(key).append("=").append(paraMap.get(key));
if(++i == keySet.size()) break;
urlParam.append("&");
}
return urlParam.toString();
}
/**
* 发起HTTP/HTTPS请求(method=POST)
* @param url
* @return
*/
public static String call4Post(String url) {
try {
URL url1 = new URL(url);
if("https".equals(url1.getProtocol())) {
return HttpClient.callHttpsPost(url);
}else if("http".equals(url1.getProtocol())) {
return HttpClient.callHttpPost(url);
}else {
return "";
}
} catch (MalformedURLException e) {
e.printStackTrace();
}
return "";
}
public static void main(String[] args) {
//_log.info("Http的Post用法");
//String reqData = "params=" + paramMap.toJSONString();
//String url = webConfig.getBase_url() + "/pay/create_order?";
//String retData = HttpUtils.call4Post(url + reqData);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy