I've already looked at many tutorials, but I am stumped. This is the code I have so far that I've put together from several guides:
protected Boolean doInBackground(Void... params) {
// TODO: attempt authentication against a network service.
try {
// Create URL
url = baseUrl + "signin?username=" + mEmail + "&password=" + mPassword + "&remember_me=true&accept_terms=true";
// Next, we create a new JsonArrayRequest. This will use Volley to make a HTTP request
// that expects a JSON Array Response.
// To fully understand this, I'd recommend readng the office docs: https://developer.android.com/training/volley/index.html
JsonArrayRequest arrReq = new JsonArrayRequest(Request.Method.GET, url,
new Response.Listener<JSONArray>() {
@Override
public void onResponse(JSONArray response) {
// Check the length of our response
if (response.length() > 0) {
for (int i = 0; i < response.length(); i++) {
try {
JSONObject jsonObj = response.getJSONObject(i);
String repoName = jsonObj.get("name").toString();
String lastUpdated = jsonObj.get("updated_at").toString();
} catch (JSONException e) {
// If there is an error then output this to the logs.
Log.e("Volley", "Invalid JSON Object.");
}
}
} else {
}
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// If there a HTTP error then add a note to our repo list.
Log.e("Volley", error.toString());
}
}
);
// Add the request we just defined to our request queue.
// The request queue will automatically handle the request as soon as it can.
requestQueue.add(arrReq);
// Simulate network access.
Thread.sleep(2000);
} catch (InterruptedException e) {
return false;
}
for (String credential : DUMMY_CREDENTIALS) {
String[] pieces = credential.split(":");
if (pieces[0].equals(mEmail)) {
// Account exists, return true if the password matches.
return pieces[1].equals(mPassword);
}
}
// TODO: register the new account here.
return false;
}
The api I am trying to use is: https://neurofit.me/nfoidc/api/swagger-ui#/ I want to implement a sign in function in my app, so I want to call the signin function. I have the email and password that the user puts in, but there are other parameters like accept-language and user-agent that are called headers.
I am extremely confused as to how I can just send in the email and password and get back a JSON file. I also don't think I am constructing the URL correctly.