我正在尝试使用Volley将数据发送到服务器而我无法从服务器中检索数据,下面是我的凌空代码 -
final RequestQueue Q = Volley.newRequestQueue(MainActivity.this);
//Handler h = new Handler();
final JsonObjectRequest get_j = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
//set_t();
public void onResponse(JSONObject response) {
try {
Q.stop();
//t.setText(response.getString("ip"));
if(response.getString("STATUS").equals("PASS")){
t.setText(response.getString("ID"));
}
else{
t.setText("Oops..! Some thing went wrong");
}
} catch (JSONException e) {
t.setText("Error...");
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Q.stop();
t.setText(error.getMessage());
error.printStackTrace();
}
}){
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String,String> params = new HashMap<String,String>();
params.put("ADDRESS_TYPE","3");
params.put("DOOR_NO","XYZ/123");
return params;
}
};
Q.add(get_j);
以下是PHP Server的代码 -
<?php $data["STATUS"] = "PASS"; $data["ID"] = "xx".$_GET['DOOR_NO']; echo json_encode($data); ?>