Das folgende Ereignis wird bei einem Buttonklick in Android ausgelöst und soll eine post-Anfrage an den Rails Server mit params stellen. Derselbe Code scheint in der Vergangenheit zu funktionieren, nicht sicher, was jetzt schief gelaufen ist.
Beim Debuggen bewegt sich der Cursor/Steuerelement vom Erstellen von JSONObject - js zu JsonObjectRequest jsonObjReq = new JsonObjectRequest (...) und dann zu queue.add (jsonObjReq); folgende Fehlermeldung erscheint: - Nachricht in Android-Studiomonitor - D/Volley: [1] 2.onErrorResponse: ShoppingCartActivityJSON Objekt Volley Beitragsanfrage - Server kann nicht gefunden werden - Rails local URL gebunden an Adresse 192.168.0.3
Alle/Alle Vorschläge sind willkommen.
-Code hier: -
bCheckOut.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
final String LOGIN_URL = "http://192.168.0.3:3000/shopping/cart_items";
RequestQueue queue = Volley.newRequestQueue(ShoppingCartActivity.this);
final String access_token = "sWbxDJrF6SrB+DdWXLavoBz2LjiA5QCns5S6DMb7N4rDTWuHfcVYQ/1HxwHOq2fw7xXU4pXAjFw==“; //test purposes.
Log.d(TAG, "Shopping cart item list: " + " Shopping cart items . " + LOGIN_URL);
JSONObject js = new JSONObject();
try {
JSONObject jsonobject_one = new JSONObject();
jsonobject_one.accumulate("variant_id", "4217");
jsonobject_one.accumulate("quantity", "1");
JSONObject jsonobject_TWO = new JSONObject();
jsonobject_TWO.accumulate("authenticity_token", access_token);
jsonobject_TWO.accumulate("utf8", "tick");
jsonobject_TWO.accumulate("name", "Rakesh");
JSONObject jsonobject = new JSONObject();
jsonobject.accumulate("requestinfo", jsonobject_TWO);
js.accumulate("authenticity_token", access_token);
js.accumulate("utf8", "tick");
js.accumulate("name", "Rakesh");
js.accumulate("cart_item", jsonobject_one);
//js.accumulate("Parameters", jsonobject);
}catch (JSONException e) {
e.printStackTrace();
}
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.POST,LOGIN_URL, js,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.d(TAG, response.toString());
//msgResponse.setText(response.toString());
//hideProgressDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d(TAG, "Error: " + error.getMessage());
//hideProgressDialog();
}
}) {
/**
* Passing some request headers
*/
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
};
//ApplicationController.getInstance().addToRequestQueue(postRequest);
queue.add(jsonObjReq);
}
});