I am making rest api call in my spring project. The url is : https://testinfo.com/user-api/rest/userinfo?uploadStartTime=1476882000&uploadEndTime=1476907200
Here is my code:
public String getUserData(String uplaodStartTime,String uplaodEndTime) throws IOException{
String user_url = https://testinfo.com/user-api/rest/userinfo
String url = user_url + "?" + "uploadStartTime" + "=" +uplaodStartTime + "&"
+ "uploadEndTime" + "=" + uplaodEndTime;
URL obj = new URL(url);
HttpURLConnection con = (HttpURLConnection) obj.openConnection();
con.setRequestMethod("GET");
int responseCode = con.getResponseCode();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
return response.toString();
}
Is there any best way to make a rest api call without hard coding the url parameters?