ITeye博客

java模拟调用Servlet

JavaSam · 2013-12-26 13:27 · JAVA · 编程语言 · Markdown

public static void main(String[] args) throws Exception	{
		Properties property = new Properties();
		BufferedInputStream inBuff = null;
		inBuff = new BufferedInputStream(new PostRequestEmulator().getClass().getResourceAsStream("/attach.properties"));
		property.load(inBuff);
		// 服务地址
		URL url = new URL(property.getProperty("key"));
		// 设定连接的相关参数
		HttpURLConnection connection = (HttpURLConnection) url.openConnection();
		connection.setDoOutput(true);
		connection.setRequestMethod("POST");
		// 获取服务端的反馈
		String strLine = "";
		String strResponse = "";
		InputStream in = connection.getInputStream();
		BufferedReader reader = new BufferedReader(new InputStreamReader(in));
		while ((strLine = reader.readLine()) != null){
			strResponse += strLine + "\n";
		}
		System.out.print(strResponse);
	}

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。