所需依赖为
引入依赖为
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.PostMethod;
特别说明 tmpString为json对象
System.out.println("tmpString = " + tmpString);// 处理发送https 错误问题SSLContext context = SSLContext.getInstance("TLSv1.2");context.init(null, null, null);SSLContext.setDefault(context);HttpClient httpclient = new HttpClient();PostMethod postmethod = new PostMethod(serverUrl);postmethod.addRequestHeader("accept", "*/*");postmethod.addRequestHeader("Content-Type", "application/json");postmethod.setRequestBody(tmpString);int code = httpclient.executeMethod(postmethod);System.out.println("code = " + code);