测试

@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);
}

posted @ 2017-09-16 20:08  zhgs_cq  阅读(110)  评论(0编辑  收藏  举报