我试图从我的结果集的两个部分构建一个url。 Prop_Value本身就是一个URL,但我需要在它的末尾添加一个Ven_Item。这是我的代码涉及构建:
{{1}}
它会一直运行,但它只发送过PROP_VALUE并且没有将VEN_ITEM附加到它,任何建议?
答案 0 :(得分:0)
我认为你的第一个和第二个变量值有问题。请检查。 Bcoz,下面的代码运行正常。
String first = ("https://stackoverflow.com/questions");
String second = ("/48545905/putting-2-strings-together-to-build-url-with-resultset");
String url = (first+second);
URL obj = null;
try {
obj = new URL(url);
} catch (MalformedURLException e) {
e.printStackTrace();
}
HttpsURLConnection con = null;
try {
con = (HttpsURLConnection) obj.openConnection();
} catch (IOException e) {
e.printStackTrace();
}
int responseCode = con.getResponseCode();
System.out.println("\nSending 'GET' request to URL : " +url);
System.out.println("Response Code : " + responseCode);
BufferedReader in = new BufferedReader(
new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer content = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
content.append(inputLine);
}
System.out.println(content);
in.close();
con.disconnect();
获得下面的控制台输出:
向网址发送'GET'请求: Putting 2 Strings Together to Build URL with ResultSet 回复代码:200