Last active
June 26, 2020 02:15
-
-
Save lokcito/504aa3ef55ec2b6e0feee6db582640a1 to your computer and use it in GitHub Desktop.
Enviamos una petición POST a un API Rest, http://equisd.com/consumir-api-rest-con-android-listview/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void sendRequestPOST(QueueUtils.QueueObject o, final MainActivity _interface) { | |
String url = "http://rrojasen.alwaysdata.net/purchaseorders.json"; | |
url = "http://fipo.equisd.com/api/users/new.json"; | |
url = "http://192.168.58.3:8056/api/users/new.json"; | |
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, | |
new Response.Listener<String>() { | |
@Override | |
public void onResponse(String response) { | |
try { | |
//Do it with this it will work | |
JSONObject _response = new JSONObject(response); | |
if (_response.has("object")) { | |
JSONObject object_response = null; | |
try { | |
object_response = _response.getJSONObject("data"); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
if ( object_response != null ) { | |
try { | |
System.out.println(object_response.getInt("id")); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} | |
}, | |
new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
} | |
}){ | |
@Override | |
protected Map<String,String> getParams(){ | |
Map<String,String> params = new HashMap<String, String>(); | |
params.put("first_name","aaa"); | |
params.put("last_name","ddd"); | |
params.put("avatar","xxx"); | |
return params; | |
} | |
}; | |
o.addToRequestQueue(stringRequest); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void sendRequestPOST(QueueUtils.QueueObject o, final MainActivity _interface) { | |
String url = "http://rrojasen.alwaysdata.net/purchaseorders.json"; | |
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest | |
(Request.Method.POST, url, null, new Response.Listener<JSONObject>() { | |
@Override | |
public void onResponse(JSONObject response) { | |
if (response.has("data")) { | |
JSONObject object_response = null; | |
try { | |
object_response = response.getJSONObject("data"); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
if ( object_response != null ) { | |
try { | |
System.out.println(object_response.getInt("id")); | |
} catch (JSONException e) { | |
e.printStackTrace(); | |
} | |
} | |
} | |
} | |
}, new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
// TODO: Handle error | |
} | |
}); | |
o.addToRequestQueue(jsonObjectRequest); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void sendRequestPOST(QueueUtils.QueueObject o, final MainActivity _interface) { | |
String url = "http://rrojasen.alwaysdata.net/purchaseorders.json"; | |
url = "http://fipo.equisd.com/api/users/new.json"; | |
url = "http://192.168.58.3:8056/api/users/new.json"; | |
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, | |
new Response.Listener<String>() { | |
@Override | |
public void onResponse(String response) { | |
//Here your code when the request is successful | |
} | |
}, | |
new Response.ErrorListener() { | |
@Override | |
public void onErrorResponse(VolleyError error) { | |
//Here your code when the request was going fatal | |
} | |
}){ | |
@Override | |
protected Map<String,String> getParams(){ | |
Map<String,String> params = new HashMap<String, String>(); | |
params.put("first_name","aaa"); | |
params.put("last_name","ddd"); | |
params.put("avatar","xxx"); | |
return params; | |
} | |
}; | |
o.addToRequestQueue(stringRequest); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment