<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
public static String method2() throws IOException {
PostMethod postMethod = new PostMethod("http://113.16.167.157:8181/api/xxgl/tbkp.do") ;
postMethod.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8") ;
NameValuePair[] data = {
new NameValuePair("appid","xxxxx"),
new NameValuePair("serviceid","xxxxx"),
new NameValuePair("content","xxxxx"),
new NameValuePair("signType","xxxxx")
};
postMethod.setRequestBody(data);
HttpClient httpClient = new HttpClient();
int response = httpClient.executeMethod(postMethod);
String result = postMethod.getResponseBodyAsString() ;
if (response == 200 && result != null) {
System.out.println(result);
}
return "";
}
|