我有下面的代码来使用独立的 Java 程序进行 HTTP 调用,有人可以告诉我哪一行/方法实际上对 URL 进行了 HTTP 调用。
根据下面的代码,我了解我正在获取一个连接对象并将请求方法类型提供为“GET”,并为其提供授权详细信息。
HttpURLConnection connection = (HttpURLConnection) new URL("<Some URL String>").openConnection();
connection.setRequestMethod("GET");
BASE64Encoder enc = new BASE64Encoder();
StringBuffer userpassword = new StringBuffer().append(username).append(":").append(password);
String encodedAuthorization = enc.encode(userpassword.toString().getBytes());
connection.setRequestProperty("Authorization", "Basic " + encodedAuthorization);
BufferedReader serverResponse = new BufferedReader(new InputStreamReader(connection.getInputStream()));
// Read the response
String line;
StringBuffer response = new StringBuffer();
while ((line = serverResponse.readLine()) != null) {
response.append(line);
}
谢谢!