0

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");
    }
5
  • You should authorize first. Commented Apr 27, 2013 at 6:54
  • @Bart point is how i am new at java :P Commented Apr 27, 2013 at 7:01
  • You should read the documentation before using it. parse.com/docs Commented Apr 27, 2013 at 7:04
  • parse.com/tutorials/get-started-with-android Commented Apr 27, 2013 at 7:14
  • @Bart I am not using android SDK i am workign on the REST API with HTTP requests Commented Apr 27, 2013 at 7:18

1 Answer 1

1

Try setting the custom headers as documented:

Authentication is done via HTTP headers. The X-Parse-Application-Id header identifies which application you are accessing, and the X-Parse-REST-API-Key header authenticates the endpoint.

URL url = new URL("...");
URLConnection conn = url.openConnection();
conn.setRequestProperty("X-Parse-Application-Id", "...");
conn.setRequestProperty("X-Parse-REST-API-Key", "...");
JSONTokener tokener = new JSONTokener(conn.getInputStream());
...
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.