I am using parses REST API to get a version ID for my program and when i am trying to connect the java program returns IOException with 401 error but when i connect to that with the browser i get the JSON format correctly why?
I am getting this error.
java.io.IOException: Server returned HTTP response code: 401 for URL: https://[email protected]/1/classes/NicksNoteVersion/xngGDAa1k3
at sun.net.www.protocol.http.HttpURLConnection.getInputStream(Unknown Source)
at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(Unknown Source)
at java.net.URL.openStream(Unknown Source)
at startup.Launcher.main(Launcher.java:26)
`
My program code is :
try{
URL url = new URL("https://XXXXXX:[email protected]/1/classes/NicksNoteVersion/xngGDAa1k3");
JSONTokener tokener = new JSONTokener(url.openStream());
JSONObject json = new JSONObject(tokener);
}catch(Exception e){
e.printStackTrace();
System.out.println("Version retrieval failed");
}