这个jar包,在2007年之后就没有更新过了, 是比较老的版本了。追求新的版本 用HttpComponents 比较好

引入的jar包为:

<!---->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>

 

具体实现类为:

importimportimportimportimportimportimportimportimportpublic classprivate static Logger logger = LoggerFactory.getLogger(HttpClientHelper.class);

private/**@param@param*/
public static, url, paramJson);

//new//);
//new//);
postMethod.addRequestHeader("Content-Type", "application/json");
try//json格式的参数解析
RequestEntity entity = new StringRequestEntity(paramJson, "application/json", "UTF-8");
postMethod.setRequestEntity(entity);

httpClient.executeMethod(postMethod);
String result =returncatch, url, paramJson, e.getMessage(), e);
}
return null;
}

/**@param*/
public static, urlParam);
//new//);
//new//);
getMethod.addRequestHeader("Content-Type", "application/json");
try, result);
returncatch, urlParam, e.getMessage(), e);
}
return null;
}

public static void;
String param = "{\"aaa\":\"bbbbbbb\"}";
sendPost(url, param);
String urlParam = "https://jiashubing.cn/talk/document?fileid=1234";
sendGet(urlParam);
}

}