how to parse JSON using Volley - android

i am using volley library for post data over api...in here the Content-Type is "application/json" ....
how can i implement this type of json data :
URL: Base_URL + dorequisition
{
"submitted_by_employee_id": 1,
"name": "Technolive SF for TC",
"bags_thana_wise": [
{
"tiger": "10000",
"extreme": "5000",
"opc": "3000",
"three_rings": "4000",
"buffalo_head": "2000",
},
],
"free_bag": "500",
"landing_price": "450",
"transport_cost_ex_factory_rate": "450",
"amount_taka": "four hundred fifty",
"bank_name": "IFIC Bank Limited",
"delivery_point": "Banani",
"upto_today": "450",
"bag_type": "swing",
"remark": "Good Cement",
"token": "2cbf1cefb6fe93673565ed2a0b2fd1a1"
}
api implementation sample :
public void APIRetailVisitInfo() {
for (int i = 0; i < retailVisitInfoList.size(); i++) {
System.out.println("token id:::" + token + " :::"+employee_id);
Map<String, String> jsonParams = new HashMap<String, String>();
jsonParams.put("submitted_by_employee_id", employee_id);
jsonParams.put("retailer_name", retailVisitInfoList.get(i).getRetails_name());
jsonParams.put("retailer_phone", retailVisitInfoList.get(i).getRetailer_contact_no());
jsonParams.put("retailer_address", retailVisitInfoList.get(i).getRetails_address());
jsonParams.put("remarks", retailVisitInfoList.get(i).getRemarks());
jsonParams.put("token", token);
JsonObjectRequest myRequest = new JsonObjectRequest(
Request.Method.POST,
"http://technolive.co/retailvisitinfo",
new JSONObject(jsonParams),
new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
code = response.getString("code");
//token = response.getString("token");
} catch (JSONException e) {
e.printStackTrace();
}
if (code.equals("200")) {
System.out.println("APICompetetorBasedOnMArketPrice:::" + code + " :::");
}
// System.out.println("token:::" + token+" :::");*/
// verificationSuccess(response);
System.out.println("APICompetetorBasedOnMArketPrice:::" + response + " :::");
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
// verificationFailed(error);
}
}) {
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
String auth = token;
headers.put("Content-Type", "application/json; charset=utf-8");
headers.put("User-agent", "My useragent");
// headers.put("Authorization", auth);
return headers;
}
};
RequestQueue requestQueue = Volley.newRequestQueue(RetailVisitInfoActivity.this);
requestQueue.add(myRequest);
// MyApplication.getInstance().addToRequestQueue(myRequest, "tag");
}
}
can anyone help me please........

It is rather simple. First let's start with bags_thana_wise. bags_thana_wise is a JSONArray. It contains one object. So lets create the object.
JSONObject json1 = new JSONObject();
json1.put("tiger","10000";
json1.put("extreme","5000";
and so on..Now put this json object into an array
JSONArray jsonArray = new JSONArray();
jsonArray.put(json1);
Now just add this array and other values to another json object
JSONObject finalObject = new JSONObject();
finalObject.put("submitted_by_employee_id","1");
finalObject.put("name","Technolive SF for TC");
//put the jsonArray
finalObject.put("bags_thana_wise",jsonArray);
finalObject.put("free_bag","500");
.
.
.
finalObject.put("token","2cbf1cefb6fe93673565ed2a0b2fd1a1");
Now make the following volley request
JsonObjectRequest jsonReq = new JsonObjectRequest(Request.Method.POST,
myURL, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
//Handle response
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(PopupActivity.this,"Can not reach server",Toast.LENGTH_LONG).show();
}
}){
#Override
public String getBodyContentType(){
return "application/json; charset=utf-8";
}
#Override
public byte[] getBody() {
try {
return finalObject == null ? null: finalObject.getBytes("utf-8");
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
return null;
}
}
};
RequestQueue requestQueue = Volley.newRequestQueue(RetailVisitInfoActivity.this);
requestQueue.add(jsonRequest);

Related

PUT Request for Json with Json array inside

I'm trying to update a PUT request which has a JSONArray inside it and I'm constantly getting a 500 error response. Here how the api structure is:
{
"imei": 514515854152463,
"franquia": "SAO",
"sistema": "PEGASUS",
"lista": 2055313,
"entregas":[
{
"codHawb": "02305767706",
"dataHoraBaixa": "2020-12-03T15:26:22",
"foraAlvo": 1000,
"latitude": 44.4545,
"longitude": 45.545,
"nivelBateria": 98,
"tipoBaixa": "ENTREGA"
}
]
}
I've tried the api in Postman to see if its working and it is. But when I'm trying it in the program using Volley I'm getting that error. I've tried volley and here is the code:
private void PutJsonRequest() {
try {
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("imei", "514515854152463");
postParam.put("franquia", preferences.getFranchise());
postParam.put("sistema", preferences.getSystem());
postParam.put("lista", preferences.getListID());
postParam.put("dataHoraBaixa", "2020-12-03T15:26:22");
postParam.put("foraAlvo", "100");
postParam.put("latitude", "45.545");
postParam.put("longitude", " 45.554");
postParam.put("nivelBateria", "98");
postParam.put("tipoBaixa", "ENTREGA");
JsonObjectRequest request = new JsonObjectRequest(Request.Method.PUT, ApiUtils.GET_LIST + preferences.getListID(), new JSONObject(postParam), new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.e(TAG, "PUTonResponse: " + response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "PUTonResponseError: " + error);
}
}) {
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
String auth1 = "Basic "
+ Base64.encodeToString((preferences.getUserName() + ":" + preferences.getPass()).getBytes(),
Base64.NO_WRAP);
params.put("Authorization", auth1);
params.put("x-ver", "3.0");
params.put("x-ras", "rick");
params.put("Content-Type", "application/json");
return params;
}
#Override
public String getBodyContentType() {
return "application/json";
}
};
queue.add(request);
} catch (Exception e) {
e.printStackTrace();
}
}
Here is the result in postman:1
Here is the result in postman:2
The problem is there is an array in the api, I've tried the above in the way if there are only JSON object but it is not working, please help me know if anything can be updated or done in different way for sending arrays either in volley or retrofit. Thanks.
//Edit:
I tried sending the params in another way and this was also giving the same 500 error:
JSONArray jsonArray=new JSONArray();
JSONObject jsonObj=new JSONObject();
try {
jsonObj.put("codHawb", "02305767706");
jsonObj.put("dataHoraBaixa", "2020-12-03T15:26:22");
jsonObj.put("foraAlvo", "100");
jsonObj.put("latitude", "-46.86617505263801");
jsonObj.put("longitude", " -23.214458905023452");
jsonObj.put("nivelBateria", "98");
jsonObj.put("tipoBaixa", "ENTREGA");
jsonArray.put(jsonObj);
Map<String, String> postParam = new HashMap<String, String>();
postParam.put("imei", "514515854152463");
postParam.put("franquia", preferences.getFranchise());
postParam.put("sistema", preferences.getSystem());
postParam.put("lista", preferences.getListID());
postParam.put("entregas",jsonArray.toString());
Finally figured it out, sending the PUT request in the form of api. FYI: If you have multiple json objects inside the array, just use a for loop, here is the working answer:
private void PutJsonRequest() {
JSONArray jsonArray=new JSONArray();
JSONObject jsonObj=new JSONObject();
JSONObject jsonObj1=new JSONObject();
try {
jsonObj.put("codHawb", "02305767706");
jsonObj.put("dataHoraBaixa", "2020-12-03T15:26:22");
jsonObj.put("foraAlvo", "100");
jsonObj.put("latitude", "45.222");
jsonObj.put("longitude", " 23.23452");
jsonObj.put("nivelBateria", "98");
jsonObj.put("tipoBaixa", "ENTREGA");
jsonArray.put(jsonObj);
jsonObj1.put("imei", preferences.getIMEI());
jsonObj1.put("franquia", preferences.getFranchise());
jsonObj1.put("sistema", preferences.getSystem());
jsonObj1.put("lista", preferences.getListID());
jsonObj1.put("entregas", jsonArray);
Log.e(TAG, "PutJsonRequest: "+jsonObj1 );
JsonObjectRequest request = new JsonObjectRequest(Request.Method.PUT, ApiUtils.GET_LIST + preferences.getListID(),jsonObj1, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.e(TAG, "PUTonResponse: " + response);
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e(TAG, "PUTonResponseError: " + error);
}
}) {
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> params = new HashMap<String, String>();
String auth1 = "Basic "
+ Base64.encodeToString((preferences.getUserName() + ":" + preferences.getPaso()).getBytes(),
Base64.NO_WRAP);
params.put("Authorization", auth1);
params.put("x-versao-rt", "3.8.10");
params.put("x-rastreador", "ricardo");
// params.put("Content-Type", "application/json");
params.put("Content-Type", "application/json; charset=utf-8");
return params;
}
#Override
public String getBodyContentType() {
return "application/json; charset=utf-8";
}
};
request.setTag(TAG);
queue.add(request);
} catch (Exception e) {
e.printStackTrace();
}
}
Comment if anyone has a doubt.

How to set object to VolleyRequest(POST Request) in this type of API?

I have an API link to send post request for creating the order,
I tried to set Request in this way.
I want to send POST request same as request to send in my image (Postman).
I want to create order from cart using cartID and index of the cart, how to send please help me out from this.
Thank You :
public void postCreateOrderByCustomer(ArrayList<CartItem> cartItems) {
String token = sharedPreferences.getString(Constant.token, null);
String endPoint = "https://prettyyou.in/cake/pos/api/customers/create-order?token=" + token;
JSONObject jsonObject = new JSONObject();
JSONArray jsonArray = new JSONArray();
Map<String, String> payloadParams = new HashMap<String, String>();
for (int i = 0; i < cartItems.size(); i++) {
payloadParams.put("cart[" + i
+ "][id]", cartItems.get(i).getId());
}
Log.d(TAG, "postCreateOrderByCustomer: " + jsonObject);
System.out.println("endPointCartGet" + " " + endPoint.toString());
jsonObject = new JSONObject(payloadParams);
Log.d(TAG, "postCreateOrderByCustomer: " + jsonObject);
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, endPoint, jsonObject, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
try {
Log.d(TAG, "onResponseCustomer: " + response);
if (response.getBoolean("status")) {
Constant.orderId = response.getString("order_id");
Intent intent = new Intent(DeliveryDetailsActivity.this, PaymentDetailsActivity.class);
startActivity(intent);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.d(TAG, "onErrorResponse: " + error.toString());
}
}) {
#Override
protected Map<String, String> getParams() throws AuthFailureError {
return payloadParams;
}
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
return super.getHeaders();
}
};
RequestQueue queue = Volley.newRequestQueue(DeliveryDetailsActivity.this);
queue.add(jsonObjectRequest);
}
You can also use Stringrequest and object request or Jsonobject requst

How to parse JSON using Volley?

i have some json output like this
{
"message": "success",
"battery": "AHAJAJ1DH13T0021",
"data": {
"id": 6,
"userId": 3,
"shopId": 1,
"transactionStatus": "PENDING",
"expiredAt": "2019-01-04T03:01:18.878Z",
"updatedAt": "2019-01-04T02:01:18.916Z",
"createdAt": "2019-01-04T02:01:18.916Z",
"paymentId": null,
"batteryNo": null
},
"shopData": {
"id": 1,
"name": "test1",
"tel": "555",
"address": "cikarang",
"description": "showroom",
"latitude": "-6.307923199999999",
"longitude": "107.17208499999992",
"open_time": "10.00",
"battery_available": 16,
"battery_booked": 1,
"status": 1,
"createdAt": "2018-12-28T03:59:55.156Z",
"updatedAt": "2019-01-04T02:01:18.940Z"
}
}
and i implement using volley like this
StringRequest request = new StringRequest(Request.Method.POST, ApiService.ORDER_BATTERY, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try{
BookBattery bookBattery = new BookBattery();
JSONObject jsonObject = new JSONObject(response);
if (!jsonObject.has("success")) {
JSONObject object = jsonObject.getJSONObject("battery");
String data = object.getString("");
JSONArray jsonArray = jsonObject.getJSONArray("data");
} else {
Log.e("Your Array Response", "Data Null");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("error is ", "" + error);
}
}) {
//This is for Headers If You Needed
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json; charset=UTF-8");
params.put("token", TokenUser);
return params;
}
//Pass Your Parameters here
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("shopId", String.valueOf(shopId));
//params.put("Pass", PassWord);
return params;
}
};
AppController.getInstance().addToRequestQueue(request, tag_json_obj);
but not working, please help thanks a lot
Use http://jsonviewer.stack.hu/ [To see json data structure]
braces {} its an JSONObject
brackets [] its an JSONArray
public void parseJson() {
try {
JSONObject jsonObject = new JSONObject(jsonParsing);
boolean isSuccess = jsonObject.getString("message").contains("success");
if (isSuccess) {
JSONObject jsonObjectData = jsonObject.getJSONObject("data");
String userId = jsonObject.getString("userId");
JSONObject jsonObjectShopData = jsonObject.getJSONObject("shopData");
String name = jsonObject.getString("tel");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
You are not getting JSONArray anywhere, your response object has multiple JSONObject
JSONObject jsonObject = new JSONObject(response);
if (!jsonObject.has("success")) {
JSONObject object = jsonObject.getJSONObject("battery");
JSONOnject jsonObject2= jsonObject .getJSONObject("data");// here you need to change.
String batteryNo=jsonObject2.getJSONObject("batteryNo");
JSONOnject jsonObject3= jsonObject1.getJSONObject("shopData");
String address=jsonObject2.getJSONObject("address");
} else {
Log.e("Your Array Response", "Data Null");
}
You can use some lib for Volley (e.g. VolleyEx), together with Gson, to parse the JSON Object to a Map in Java.
i.e. using GsonObjectRequest instead of StringRequest
developer.android.com has the code, but there are also libs doing that for you.
example HERE
Try this
StringRequest request = new StringRequest(Request.Method.POST, ApiService.ORDER_BATTERY, new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try{
BookBattery bookBattery = new BookBattery();
JSONObject jsonObject = new JSONObject(response);
String message = jsonObject.getString("message");
if (message.equalsIgnoreCase("success")) {
String battery = jsonObject.getString("battery");
JSONObject dataObject = jsonObject.getJSONObject("data");
JSONObject shopDataObject = jsonObject.getJSONObject("shopData");
int dataId = dataObject.getInt("id");
int dataUserId = dataObject.getInt("userId");
int dataShopId = dataObject.getInt("shopId");
} else {
Log.e("Your Array Response", "Data Null");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Log.e("error is ", "" + error);
}
}) {
//This is for Headers If You Needed
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("Content-Type", "application/json; charset=UTF-8");
params.put("token", TokenUser);
return params;
}
//Pass Your Parameters here
#Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("shopId", String.valueOf(shopId));
//params.put("Pass", PassWord);
return params;
}
};
AppController.getInstance().addToRequestQueue(request, tag_json_obj);
here i only parse "id", "userId" & "shopId" from dataObject. Rest can be parse in similar way.
Before do it I will suggest you please read about the json Array and Json Object.
Here the solution.
HashMap<String, String> params = new HashMap<String, String>();
params.put("your json parameter name", json parameter value);
// params.put("device_id", deviceID);
Log.d("response11", String.valueOf(params));
String Url ="your server url";
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, Url,
new JSONObject(params), new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject response) {
Log.d(TAG + "JO", String.valueOf(response));
try {
String msgObject = response.getString("message");
Log.d("response","msgObject");
}catch (JSONException e){
String jsonExp = e.getMessage();
Log.d(TAG + "JE", jsonExp);
}
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
String volleyErr = error.getMessage();
Log.d(TAG + "VE", volleyErr);
}
});
requestQueue.add(jsonObjectRequest);
this sufficient for print you server response. check response in logcat.

Android Volley calling oData using Request.POST giving 403 Error

I am calling SAP's oData Service using Volley API from Android and getting HTTP 403 Error for the Request.POST. But for the Request.GET for another Service program is working fine. May I know if there is any issue with my code calling oData Service.
Iam passing MYSAPSSO2 token and CSRF Token obtained from my first request call. But getting Authentication error. Any idea what is missing here?
Same oData POST service using JQUERY/SAPUI5 is working fine without any issues.
try {
/** json object parameter**/
JSONObject jsonObject = new JSONObject();
jsonObject.put("SO", so);
jsonObject.put("STATUS", status);
jsonObject.put("NET_VALUE", amount);
Log.i("XXXX", thisMethod+"jsonObject params"+ jsonObject.toString() + "");
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
#Override
public void onResponse(JSONObject jsonRespObj) {
Log.i("XXXX", thisMethod+"Response from notification service: " + jsonRespObj.toString());
}
}, new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError volleyError) {
Log.i("XXXXX", thisMethod+"Error Response: " + volleyError);
volleyError.printStackTrace();
}
}
) {
#Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
if (mysapsso2 != null) {
Log.i("XXX", thisMethod+"MYSAPSSO2 is : " + TokenHandler.getMYSAPSSO2Token());
Log.i("XXXX", thisMethod+"X-CSRF-Token is : " + TokenHandler.getCSRFToken());
params.put("Cookie", ServiceClass.mysapsso2);
params.put("X-CSRF-Token", TokenHandler.getCSRFToken());
params.put("contentType", "application/json");
}
return params;
}
};
queue.add(jsonObjectRequest);
} catch (JSONException e) {
Log.e("XXX", thisMethod+"There was an error => " + e.getMessage());
e.printStackTrace();
}
catch (Exception e) {
Log.e("XXXX", thisMethod+"There was an error => " + e.getMessage());
e.printStackTrace();
}
Use StringRequest insted of JsonObjectRequest. Get json encoded response to a string & create json object. Below code work fine for me. try it.
public void getPostJsonData() {
final String URL = "URL";
StringRequest stringRequest = new StringRequest(Request.Method.POST, URL,
new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject obj = new JSONObject(response);
JSONArray jsonArray = obj.getJSONArray("server_response");
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject JO = jsonArray.getJSONObject(i);
fname = JO.getString("firstname"); //or JO.toString()
lname = JO.getString("lastname");
}
} catch (JSONException e) {
e.printStackTrace();
}
}
},
new Response.ErrorListener() {
#Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(ActivityName.this, error.toString(), Toast.LENGTH_LONG).show();
}
}) {
#Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String, String> hashMap = new HashMap<String, String>();
hashMap.put("Cookie", ServiceClass.mysapsso2.toString);
hashMap.put("X-CSRF-Token", TokenHandler.getCSRFToken().toString);
hashMap.put("contentType", "application/json");
return hashMap;
}
};
final RequestQueue requestQueue = Volley.newRequestQueue(this);
requestQueue.add(stringRequest);
requestQueue.addRequestFinishedListener(new RequestQueue.RequestFinishedListener<Object>() {
#Override
public void onRequestFinished(Request<Object> request) {
requestQueue.getCache().clear();
}
});
}

Volley Post method for json object

data={
"request": {
"type": "event_and_offer",
"devicetype": "A"
},
"requestinfo": {
"value": "offer"
}
}
how to post this request from volley plz help
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.POST,url, null ,
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/x-www-form-urlencoded");
return headers;
}
js is reffer to my jsson object ...... i make my jsson like this.....
JSONObject jsonobject_one = new JSONObject();
try {
jsonobject_one.put("type", "event_and_offer");
jsonobject_one.put("devicetype", "I");
JSONObject jsonobject_TWO = new JSONObject();
jsonobject_TWO.put("value", "event");
jsonobject = new JSONObject();
jsonobject.put("requestinfo", jsonobject_TWO);
jsonobject.put("request", jsonobject_one);
js = new JSONObject();
js.put("data", jsonobject.toString());
Log.e("created jsson", "" + js);
But it Not response the value what to do plzz help
first your json data:
JSONObject js = new JSONObject();
try {
JSONObject jsonobject_one = new JSONObject();
jsonobject_one.put("type", "event_and_offer");
jsonobject_one.put("devicetype", "I");
JSONObject jsonobject_TWO = new JSONObject();
jsonobject_TWO.put("value", "event");
JSONObject jsonobject = new JSONObject();
jsonobject.put("requestinfo", jsonobject_TWO);
jsonobject.put("request", jsonobject_one);
js.put("data", jsonobject.toString());
}catch (JSONException e) {
e.printStackTrace();
}
then your json request:
JsonObjectRequest jsonObjReq = new JsonObjectRequest(
Request.Method.POST,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;
}
Notice the header
and if you want to test in localhost use below code and set your url to connect your localhost server and ip address:
below code put all of your request in a text file, i tried it and it works
<?php
file_put_contents('test.txt', file_get_contents('php://input'));
?>

Categories

Resources