This wants to send JsonObject in key Json. So please tell how to send it using volley. json={"product":"magie"}
How to send this data in Volley, I have add the asyncTask code below for hit api with that type of data.
enter code here
protected void onPreExecute() {
if (progress)
GlobalAlerts.showProgressDialog(context);
}
@Override
protected String doInBackground(String... params) {
String resp = null;
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("product","magie");
} catch (JSONException e) {
e.printStackTrace();
}
String data = "json=" + jsonObject.toString();
String url ="http://anc.php";
resp = new JsonCall().executeHttpPostRequest(url, data);
return resp;
}
protected void onPostExecute(String resp) {
if (progress)
GlobalAlerts.hideProgressDialog();
if (resp != null) {
callback.onTaskComplete(resp);
} else {
GlobalAlerts.singleAlert((Activity) context, context.getString(R.string.warning), "Error", false);
}
}
Answer for that is like put data in jsonObject and then pass jsonObject in hashmap with key json.
enter code here
String url = "http://anc.php";
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("product", "magie");
} catch (JSONException e) {
e.printStackTrace();
}
final HashMap<String,String> hashMap2 = new HashMap<>();
hashMap2.put("json",jsonObject.toString());
StringRequest strReq = new StringRequest(Request.Method.POST,
url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("order_list", response);
GlobalAlerts.hideProgressDialog();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Error", "Error: " + error.getMessage());
GlobalAlerts.hideProgressDialog();
}
}) {
@Override
protected Map<String, String> getParams() {
/*Map<String,String> params = new HashMap<>();
params.put("employee_id"," 1");*/
return hashMap2;
}
};
Application.getInstance().addToRequestQueue(strReq, "order_list");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.