多個URL我有一個字符串數組a []包含我要傳遞到我的HTTPGET代碼如下使用數組來獲取通過HTTPGET在Java中
for (int i = 0; i < size; i++);{
try (CloseableHttpClient httpclient = HttpClients.custom().setDefaultCredentialsProvider(credsProvider).build()){
HttpGet httpget = new HttpGet(a[i]);
/*WRITE TO FILE*/
/*try (CloseableHttpResponse response = httpclient.execute(new HttpGet(a[i]))){
HttpEntity entity = response.getEntity();
if (entity != null) {
try (FileOutputStream outstream = new FileOutputStream(AgentRequirements)) {
entity.writeTo(outstream);
}
}
}*/
/*SHOW EXECUTION*/
System.out.println("Executing request " + httpget.getRequestLine());
try (CloseableHttpResponse response = httpclient.execute(httpget)) {
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
System.out.println(EntityUtils.toString(response.getEntity()));
}
}
}
幾個網址,我有一個構建失敗,因爲它說該系統找不到符號'i'。任何人都可以幫忙嗎?
你的答案更好。它真的解釋了爲什麼和如何。另外我喜歡你的信息片尾:) – Lino