Sending parameters by android url

1

I have an android application running and I need to send a few URL races quickly and easily.

I use this code to execute this function, but it is already obsolete and sometimes it does not work as it should! Thanks in advance for your help.

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();
                }
            }
        });

    }
    
asked by anonymous 31.12.2016 / 02:30

1 answer

1

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

    
11.01.2017 / 13:35