JAVA调用接口实现
public static void main(String[] args){
//请求接口路径
String url = "http://192.168.1.5/test.html";
String input = null;
InputStream inputStream = null;
BufferedReader bufferedReader = null;
StringBuilder stringBuilder = new StringBuilder();
try {
inputStream = new URL(url).openStream();
bufferedReader = new BufferedReader(new InputStreamReader(inputStream,"utf-8"));//设置编码,否则中文乱码
while ((input = bufferedReader.readLine()) != null)
stringBuilder.append(input);
} catch (Exception e) {
e.printStackTrace();
} finally {
System.out.println(stringBuilder.toString());
try {
if (inputStream != null)
inputStream.close();
if (bufferedReader != null)
bufferedReader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
©著作权归作者所有:来自51CTO博客作者lghclub的原创作品,如需转载,请注明出处,否则将追究法律责任