测试

@Test
public void test() throws Exception{

URL url;
url = new URL("http://127.0.0.1:8080/v_wbgszhang/request/testTest.any");
URLConnection conn = url.openConnection();
HttpURLConnection httpUrlConnection = (HttpURLConnection) conn;
httpUrlConnection.setRequestProperty("dataType", "json");
httpUrlConnection.setRequestProperty("Accept-Charset", "UTF-8");
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setUseCaches(false);
httpUrlConnection.setRequestMethod("POST");
httpUrlConnection.setDoOutput(true);
httpUrlConnection.setDoInput(true);
httpUrlConnection.setUseCaches(false);
httpUrlConnection.connect();
DataOutputStream out = new DataOutputStream(httpUrlConnection.getOutputStream());



String postContent = "";
//自定义参数

out.writeBytes(postContent);
out.flush();
out.close();

InputStream in = httpUrlConnection.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(in,"UTF-8"));
String result = "";
String line = "";
while((line = br.readLine()) != null) {
result = result+line;
}
System.out.println(result);
}

原文地址:https://www.cnblogs.com/zhanggaosong/p/7532571.html