【发布时间】:2011-04-08 13:26:47
【问题描述】:
我读到用java检索网页,用起来很快:
URL url = new URL("http://example.com");
HttpURLConnection connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
InputStream stream = connection.getInputStream();
// read the contents using an InputStreamReader
但是如何将用户给定的变量添加到 url 中?例如:
用户输入 x 加载页面http://example.com/x.php
我是 java 新手,如果有任何帮助,我们将不胜感激。
【问题讨论】:
-
我记得在 Java 中可以连接两个字符串,你不能使用这种技术吗? url + inputString 变成一个新的 URL 变量,这对你有意义吗?
标签: java html html-parsing