如何在JavaSpring中在同一服务器上打开多个URL路径
我是java世界的新手,我正在尝试在同一台服务器上打开多个URL。。 我正在使用JavaSpringMVC 我有一个外部服务器,需要从服务器中的不同位置检索数据 比如说,, 外部服务器具有如下URL: 4)[问题]:那么,我需要在同一服务器的另一个路径中检索另一个数据流,如何检索? 假设我需要在同一台服务器中获取数据的第二条路径 所以我的代码是这样的:如何在JavaSpring中在同一服务器上打开多个URL路径,java,spring,spring-mvc,http-redirect,Java,Spring,Spring Mvc,Http Redirect,我是java世界的新手,我正在尝试在同一台服务器上打开多个URL。。 我正在使用JavaSpringMVC 我有一个外部服务器,需要从服务器中的不同位置检索数据 比如说,, 外部服务器具有如下URL: 4)[问题]:那么,我需要在同一服务器的另一个路径中检索另一个数据流,如何检索? 假设我需要在同一台服务器中获取数据的第二条路径 所以我的代码是这样的: public String HTTPConnection(Model model) throws IOException { //>
public String HTTPConnection(Model model) throws IOException {
//>> 1) open the first path with the url <<//
URL url = new URL("http://server.data.com:1234/dataStorage/thisgate/datalist/hereA/");
URLConnection con = url.openConnection();
HttpURLConnection firstConn = (HttpURLConnection) con;
//>> 2) authentication routine, it works well <<//
//:I am not going to put all detail code here, it works fine.
//>> 3) retrieve data from the url (the first path after authentication) <<//
firstConn.setRequestMethod("GET");
BufferedReader firstPathData = new BufferedReader(new InputStreamReader(firstConn.getInputStream()));
// do the parsing and so on....
//>> 4) open the second path in the same server , How??????? <<//
URL redirectUrl = new URL("http://server.data.com:1234/dataStorage/thisgate/datalist/hereB/");
HttpURLConnection secondConn = (HttpURLConnection) redirectUrl.openConnection();
System.out.println(secondConn.getURL());
BufferedReader secondPathData = new BufferedReader(new InputStreamReader(secondConn.getInputStream()));
.....
......
公共字符串HTTPConnection(模型模型)引发IOException{
//>>1)使用url打开第一个路径2)身份验证例程,效果很好3)从url检索数据(身份验证后的第一个路径)4)在同一个服务器中打开第二个路径,如果使用Spring RestTemplate简化与web服务器的通信,那么应该更容易
查看文档-
在你的情况下,你应该根据需要执行尽可能多的请求。我想你指的是。请在
public String HTTPConnection(Model model) throws IOException {
//>> 1) open the first path with the url <<//
URL url = new URL("http://server.data.com:1234/dataStorage/thisgate/datalist/hereA/");
URLConnection con = url.openConnection();
HttpURLConnection firstConn = (HttpURLConnection) con;
//>> 2) authentication routine, it works well <<//
//:I am not going to put all detail code here, it works fine.
//>> 3) retrieve data from the url (the first path after authentication) <<//
firstConn.setRequestMethod("GET");
BufferedReader firstPathData = new BufferedReader(new InputStreamReader(firstConn.getInputStream()));
// do the parsing and so on....
//>> 4) open the second path in the same server , How??????? <<//
URL redirectUrl = new URL("http://server.data.com:1234/dataStorage/thisgate/datalist/hereB/");
HttpURLConnection secondConn = (HttpURLConnection) redirectUrl.openConnection();
System.out.println(secondConn.getURL());
BufferedReader secondPathData = new BufferedReader(new InputStreamReader(secondConn.getInputStream()));
.....
......