截击POST操作
Volley POST operation
String url = "https://www.maishainfotech.com/adinterview/interview.php";
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", response.toString());
res.setText(response.toString());
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("TAG", "Error: " + error.getMessage());
res.setText(error.toString());
}
}) {
@Override
public byte[] getBody() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("email_id", "interview@maishainfotech.com");
if (params != null && params.size() > 0) {
return encodeParameters(params, "application/x-www-form-urlencoded");
}
return null;
}
};
requestQueue.add(stringRequest);
我应该得到
{"Response":[{"fname":"Maisha","lname":"ID","type":"customer","number":"7788778878","address":"NSP,Pitampura,Delhi"}]}
作为回应,但我收到了
{"Response":[]}
你们能帮帮我吗
我尝试使用 postman
,同时将“email_id”作为键传递,并将“interview@maishainfotech.com”作为 x-www-form-urlencoded
正文部分中的值传递,然后我得到正确的回应。
测试一下
String url = "https://www.maishainfotech.com/adinterview/interview.php";
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", response.toString());
// res.setText(response.toString());
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("TAG", "Error: " + error.getMessage());
Log.e("asdasd", "onErrorResponse: "+error.getMessage() );
// res.setText(error.toString());
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("email_id", "interview@maishainfotech.com");
return params;
}
public String getBodyContentType() {
return "application/x-www-form-urlencoded; charset=UTF-8";
}
};
requestQueue.add(stringRequest);
String url = "https://www.maishainfotech.com/adinterview/interview.php";
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", response.toString());
res.setText(response.toString());
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("TAG", "Error: " + error.getMessage());
res.setText(error.toString());
}
}) {
@Override
public byte[] getBody() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("email_id", "interview@maishainfotech.com");
if (params != null && params.size() > 0) {
return encodeParameters(params, "application/x-www-form-urlencoded");
}
return null;
}
};
requestQueue.add(stringRequest);
我应该得到
{"Response":[{"fname":"Maisha","lname":"ID","type":"customer","number":"7788778878","address":"NSP,Pitampura,Delhi"}]}
作为回应,但我收到了
{"Response":[]}
你们能帮帮我吗
我尝试使用 postman
,同时将“email_id”作为键传递,并将“interview@maishainfotech.com”作为 x-www-form-urlencoded
正文部分中的值传递,然后我得到正确的回应。
测试一下
String url = "https://www.maishainfotech.com/adinterview/interview.php";
RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new com.android.volley.Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d("TAG", response.toString());
// res.setText(response.toString());
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("TAG", "Error: " + error.getMessage());
Log.e("asdasd", "onErrorResponse: "+error.getMessage() );
// res.setText(error.toString());
}
}) {
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("email_id", "interview@maishainfotech.com");
return params;
}
public String getBodyContentType() {
return "application/x-www-form-urlencoded; charset=UTF-8";
}
};
requestQueue.add(stringRequest);