How to make GET and POST requests on android with a quick and up-to-date tool?

3

I'm currently using volley for web requests. But I find this tool very slow.

I researched google for alternatives, but all the results I find are old, from 2017, 2016 down.

About org.apache.http They are said to be obsolete, among others also obsolete.

I found little information about Gson and from what I understood, I do not even think of doing web requests.

There are people who talk about Retrofit and Retrofit 2 , which I have not tested yet.

But after all, now in the year 2018, what is the best way to do this? Is there a way to use native android studio tools without installing any library that is not obsolete?

Sorry for not posting any code, as I said I did not like the volleyball because it was too slow. So I'd really like some help with a more up-to-date tool. If possible some documentation or tutorial to use.

If I did not ask the question correctly please excuse me, I do not know another way to ask about it here. And for me here is being the only place with professionals who really understands what they say and who could help me.

I'm using android studio 3.1.2 , with minSdkVersion 15 and targetSdkVersion 27

    
asked by anonymous 11.05.2018 / 02:20

1 answer

1

in build.gradle add

dependencies {
    compile 'com.koushikdutta.ion:ion:2.+'
}
depois chame em sua Activity Ion.with(Context).load(url);

example

public class Login extends AppCompatActivity {

private String TAG = "Login";

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_identidade_digital);
    EditText   mUsuarioView  = (EditText) findViewById(R.id.mUsuarioView);
    EditText   mPasswordView  = (EditText) findViewById(R.id.mPasswordView);
    Login(mUsuarioView.getText().toString(),mPasswordView.getText().toString());
}
public void Login(String user, String senha){

    Ion.with(this).load("https://wwww.meuwebservice.com.br")
            .setBodyParameter("user", user)
            .setBodyParameter("senha", senha)
            .asJsonObject().setCallback(new FutureCallback<JsonObject>() {
        @Override
        public void onCompleted(Exception e, JsonObject result) {
            if(e != null){
               // algo deu errado
                Log.d(TAG, e.toString());
            } else if (result.get("retorno").getAsString().equals("YES")) {
               //   tudo ceto trabalhe no seu retorno pegando o resultado
                //seu metodo aqui

            }

        }
    });

}

Android Asynchronous Network and Image Upload

    
11.05.2018 / 21:24