gpt4 book ai didi

java - 检索添加了用户输入的网站

转载 作者:行者123 更新时间:2023-12-01 15:53:10 24 4
gpt4 key购买 nike

我读到用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新手,所以任何帮助将不胜感激。

最佳答案

您可以像这样使用字符串连接:

final String url = "http://example.com" + "/" + userInput

然后您可以使用该字符串实例化 URL。

关于java - 检索添加了用户输入的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5595731/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com