Issue
I'm trying to connect to a server provided for me by another developer in the team. I'm using Volley, still a beginner though.
On the server there is a register method inside the user folder which is inside the API folder. I need to be able to call this method from my android app in order to signup a new user.
Here is the code I'm using.
try {
Request request = new Request(Request.Method.POST, url + "/user/register", new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Response parseNetworkResponse(NetworkResponse response) {
Toast.makeText(getApplicationContext(), "ParseNetworkRequest", Toast.LENGTH_LONG).show();
return null;
}
@Override
protected void deliverResponse(Object response) {
Toast.makeText(getApplicationContext(), "DeliverResponse", Toast.LENGTH_LONG).show();
}
@Override
public int compareTo(Object another) {
return 0;
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
// POST Parameters
params.put("api_key", API_KEY);
params.put("email", etEmail.getText().toString());
params.put("password", etPassword.getText().toString());
params.put("verifyPassword", etConfirmPass.getText().toString());
params.put("firstname", etFirstName.getText().toString());
params.put("lastname", etLastName.getText().toString());
params.put("birthday", birthDate);
return params;
}
};
Volley.newRequestQueue(this).add(request);
The error I'm getting.
com.android.volley.NoConnectionError: java.net.UnknownHostException: Unable to resolve host "<url>": No address associated with hostname
The permissions in my manifest.xml since most of the questions asked before were solved by adding this lines, didn't work in my situation.
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="ANDROID.PERMISSION.ACCESS_NETWORK_STATE" />
Note that I tried to use the RequestString class and I got the same error, but when I tried to use another url ("http://google.com") I got a server error, which is a bit nicer because we know why.
Solution
Using a different kind of connection solved the problem, I tried to run the app using 3G and it worked.
Answered By - Motassem Jalal
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.