Sending parameters by android url

Asked

Viewed 213 times

1

I have an android app running and need to send some parameters per URL quickly and easily to run.

I use this code to perform this function, but it is already obsolete and sometimes it does not work as it should! I appreciate the help of all.

public void sendRegisterTime(String id, String horaRegister, String image){
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost httpPost = new HttpPost(ipConnectionServer+dirInsertTimer);

    try{
        ArrayList<NameValuePair> valores = new ArrayList<NameValuePair>();
        valores.add(new BasicNameValuePair("cod", id));
        valores.add(new BasicNameValuePair("hora", horaRegister));
        valores.add(new BasicNameValuePair("img", image));

        httpPost.setEntity(new UrlEncodedFormEntity(valores));
        final HttpResponse resposta = httpClient.execute(httpPost);

        runOnUiThread(new Runnable() {
            @Override
            public void run() {
                try {
                   if(EntityUtils.toString(resposta.getEntity()).equals("success")){
                       successLayout();
                   }else{
                       failedLayout();
                   }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        });

    }

1 answer

1


The best lib to do this is okhttp. This lib is very reliable ... from the square.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.