I am required to input start time and end time and in swing java that I will further send to a URL to get some selected nodes created in this time using GET REST call.
URL is:
http://wisekar.iitd.ernet.in/active/api_resources.php/method/mynode
?key=YOUR_API_KEY_HERE
&startTime=START_TIME[Optional]
&endTime=END_TIME[Optional]en
The website will take take the input (time stamps) as they are given in the image.
Screenshot Of my window

Now my code is here:
class Algorithm extends JFrame implements ActionListener {
private static String ENDPOINT =
"http://wisekar.iitd.ernet.in/active/api_"
+ "resources.php/method/mynode.json?key=api_key";
Algorithm() {
// label1 = new JLabel();.....
panel = new JPanel(new GridLayout(5, 2));
//adding in panel label1,text1 ...
add(panel, BorderLayout.CENTER);
SUBMIT.addActionListener(this);
setTitle("Optimal Travel Route");
}
public void actionPerformed(ActionEvent ae) {
try {
//String value1 = text1.getText();..
URL url = new URL(ENDPOINT + "&datasetId=" + value3
+ "&startTime=" + value1 + "&endTime=" + value2);
System.out.println(url);
HttpURLConnection httpCon;
httpCon = (HttpURLConnection) url.openConnection();
httpCon.setDoInput(true);
System.out.println(httpCon.getResponseCode());
System.out.println(httpCon.getResponseMessage());
BufferedReader in = new BufferedReader(new InputStreamReader(
httpCon.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null) {
System.out.println(inputLine);
}
in.close();
} catch (IOException ex) {
Logger.getLogger(Algorithm.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
class AlgorithmDemo {
public static void main(String arg[]) {
try {
Algorithm frame = new Algorithm();
frame.setSize(450, 200);
frame.setVisible(true);
} catch (Exception e) {
JOptionPane.showMessageDialog(null, e.getMessage());
}
}
}
I have tried everything; I have commented it. Using this code, I am getting the nodes when I am typing the generated URL in the browser, but it is not giving the result on the console when I am printing. What is wrong in my code? Can someone tell me how should date and time should be passed to the GET. Please help. When I only input the data set ID, it gives me all the nodes of that data set ID. According to me, there is some problem in passing the time stamps.
Unfortunately when I ran a quick test I got an unauthorized response.
But it looks like the issue is the string is not url safe.
Yo need to ensure your spaces are converted to %20.
This will also be why it works using and browser as the browser address bar will do this for you behind the scenes.
If you use:
The arguments will be made url safe.