I was trying to run the following code to perform a login and it was working fine but I wanted to try to update it to work with HttpURLConnection
HttpPost post = new HttpPost("url");
HttpClient client = new DefaultHttpClient();
try{
JSONObject user = new JSONObject();
JSONObject userInfo = new JSONObject();
userInfo.put("password", password);
userInfo.put("email", email);
user.put("user", userInfo);
StringEntity sEntity = new StringEntity(user.toString());
post.setEntity(sEntity);
post.setHeader("Accept", "application/json");
post.setHeader("Content-type", "application/json");
return client.execute(post);
}catch(Exception e){
return null;
}
I made changes similar to the code post on the question bellow but the when I try to log in it would just stay in the same screen but if I closed the app it would come up logged in, since I store the token so that it remains in the logged in state. This means the connection was established.
I used this as a guide: POST request send json data java HttpUrlConnection
Is HttpUrlConnection
slower or more resource intensive? Did I do something wrong? I did see a too much going on in the main thread
in Android Studio, is that related? Any help or response is appreciated.