打开与网站的连接然后随后阅读该页面上的信息的首选方法是什么?关于不同部分似乎有许多具体问题,但没有明确和简单的例子.
try {
// Create a URL for the desired page
URL url = new URL("http://hostname:80/index.html");
// Read all the text returned by the server
BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
String str;
while ((str = in.readLine()) != null) {
// str is one line of text; readLine() strips the newline character(s)
}
in.close();
} catch (MalformedURLException e) {
} catch (IOException e) {
}
Run Code Online (Sandbox Code Playgroud)
当谈到"写"到URL时,我想你会想要像使用URL发送POST请求一样 示例库.
| 归档时间: |
|
| 查看次数: |
1104 次 |
| 最近记录: |