xiimoss xiimoss - 14 days ago 10
Android Question

Posting values to server in Android using HttpUrlConnection

I'm trying to create a registration page for my application and have got all the values stored in a

List<Pair<String,String>>


I've passed this through to my Class for connection to the server via an ASyncTask however after creating a HttpUrlConnection, i'm not sure how to add these parameters to my URL Connection. Every that i've looked uses NamePairValues but from the research i have performed this has been deprecated.

@Override
protected Void doInBackground(String... params) {


String username = params[0];
String firstName = params[1];
String lastName = params[2];
String email = params[3];
String password = params[4];

ConnectionHandler connection = new ConnectionHandler(ctx);

List<Pair<String, String>> args = new ArrayList<>();
args.add(new Pair<>("username", username));
args.add(new Pair<>("first_name", firstName));
args.add(new Pair<>("last_name", lastName));
args.add(new Pair<>("email", email));
args.add(new Pair<>("password", password));


connection.makeConnection(REGISTER_URL, args);
return null;
}


That's my current doInBackground.

Is there an easier methoid than using
List<Pair<String,String>>
?

EDIT: I actually ended up using volley which made this some much easier to do.

Answer

For anyone finding this later, I ended up using Volley which made the process so much easier.

Comments