// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
line = rd.readLine();
while (line != null) {
System.out.println(line);
line = rd.readLine();
}
wr.flush();
wr.close();
connection.disconnect();
But I got the below errors back
java.io.IOException: Server returned HTTP response code: 401 for URL: http://servername/rest/user/login at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1436)
at client.Class1.login(Class1.java:31)
at client.Class1.main(Class1.java:130)
Do you have any idea?
Thanks
Surender Suri
Ranch Hand
Joined: May 28, 2010
Posts: 41
posted
0
401 error is generally due to authentication failure, looks like the url you are trying to access needs basic authentication to access the url. Find out the credentials and see below code to send those in http header.
Ong Vua
Ranch Hand
Joined: Jan 24, 2008
Posts: 57
posted
0
Thanks. I got past the security thing and now I got the 406 error. Below is my code. For some reason, it does not recognize the JSON object returned. Do you have any ideas? Thanks
Ong Vua
Ranch Hand
Joined: Jan 24, 2008
Posts: 57
posted
0
I got the below error message back. Do you have any ideas?
HTTP/1.1 406 Not Acceptable: Unsupported request content type application/x-www-form-urlencoded
Thanks. I tried changing it but still got 406 error. The application/x-www-form-urlencoded is for POST since I'm posting the username and password parameters in the form.
Thanks for the article. I read that article before also and everything I put in my code follows it but still no luck