Put update object

Asked

Viewed 114 times

0

What’s wrong with my put? It was supposed to update objects in my database,but it doesn’t work correctly,it doesn’t return any errors,.

public String doInBackground(String... arg0) {
            String result = "";


            try {


                URL url = new URL("http://192.168.1.207/api/v2/bookdemo/_table/cad_users");

                JSONObject jsonObject = new JSONObject();
                String json = "";



                HttpURLConnection conn = (HttpURLConnection) url.openConnection();
                conn.setRequestProperty("Content-type", "application/json");
                conn.setRequestProperty("Accept", "application/json");
                conn.setRequestProperty("X-DreamFactory-Api-Key", "36fda24fe5588fa4285ac6c6c2fdfbdb6b6bc9834699774c9bf777f706d05a88");
                conn.setRequestProperty("X-DreamFactory-Session-Token", "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.XXXXXXXXXX.jfGbU3yjIPPfAQWTyYVQJCfEapYFnHPCYkL4T-arD4M");
                conn.setRequestProperty("Authorization", "Basic XXXXXXXXXXXX");
                conn.setRequestMethod("PUT");
                conn.setReadTimeout(15000 /* milliseconds */);
                conn.setConnectTimeout(15000 /* milliseconds */);
                conn.setDoInput(true);
                conn.setDoOutput(true);

                json = jsonObject.toString();


                jsonObject.put("id_user", id);
                jsonObject.put("tx_name", nome);
                jsonObject.put("tx_nickname", nickname );
                jsonObject.put("nu_cellphone", numcel );
                jsonObject.put("password", password );
                jsonObject.put("tx_email", email );
                Log.e("resource", jsonObject.toString());



                JSONObject resource = new JSONObject();
                JSONArray array = new JSONArray();
                array.put(json);
                resource.put("resource", array);

                System.out.println(resource.toString());


                conn.connect();

                OutputStream os = conn.getOutputStream();
                BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
                writer.write(resource.toString());

                writer.flush();
                writer.close();
                os.close();


                int responseCode = conn.getResponseCode();
                System.out.println("Chegou até aqui");


                if (responseCode == HttpsURLConnection.HTTP_OK) {
                   System.out.println("Funcionou");


                    BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
                    StringBuffer sb = new StringBuffer("");
                    String line = "";


                    while ((line = in.readLine()) != null) {

                        sb.append(line);
                        break;
                    }

Return of the systems... 07-25 14:16:32.248 21317-22373/com.example.Thiago.myapplication E/Resource: {"id_user":"2","tx_name":"Test","tx_nickname":"Test","nu_cellphone":"(11)99838-9998","password"":"12345","tx_email":"[email protected]"} 07-25 14:16:32.258 21317-22373/com.example.Thiago.myapplication I/System.oct: {"Resource":["{}"]}

  • Can you see the response that returns from the server? You are giving exception?

  • I put the systems feedback

  • The server has been configured to support the method PUT ?

No answers

Browser other questions tagged

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