1
How to update objects in my database via put json? This is my post code as an example,
public class onbuttonclickHttpPost extends AsyncTask<String, Void, String> {
protected void onPreExecute() {
}
public String doInBackground(String... arg0) {
try {
URL url = new URL("http://uri.com/api/v2/bookdemo/_table/cad_users");
JSONObject postDataParams = new JSONObject();
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.XXXXXXXXXXXX.jfGbU3yjIPPfAQWTyYVQJCfEapYFnHPCYkL4T-arD4M");
conn.setRequestProperty("Authorization", "Basic XXXXXXXXXXXXXXX");
conn.setRequestMethod("post");
conn.setReadTimeout(15000 /* milliseconds */);
conn.setConnectTimeout(15000 /* milliseconds */);
conn.setDoInput(true);
conn.setDoOutput(true);
postDataParams.put("tx_name", nome);
postDataParams.put("tx_nickname", nickname );
postDataParams.put("nu_cellphone", numcel );
postDataParams.put("password", password );
postDataParams.put("tx_email", email );
Log.e("resource", postDataParams.toString());
JSONObject resource = new JSONObject();
JSONArray array = new JSONArray();
array.put(postDataParams);
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(getPostDataString(postDataParams));
writer.write(resource.toString());
writer.flush();
writer.close();
os.close();
int responseCode = conn.getResponseCode();
Making it clear that this is my post code used only for example , I would like an example of put code to update my database.
Could be clearer?
– Thiago
Sorry, this code is for post. but I did a test with the code I found in this post take a look: https://stackoverflow.com/questions/15910677/how-to-call-put-method-from-web-apig-httpclient
– Lucas Nicodemos
Can be used for android?
– Thiago
They are components C#, if you are developing in Xamarin yes.
– Lucas Nicodemos