Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i trying to connect my project in android studio to Asp.net API and i'm using Volley Lib to Get Json Request but he did'nt read the response and I getting this massage in Log ((( E/Volley: [352] BasicNetwork.performRequest: Unexpected response code 400 for http://10.10.4.150:61511/api/Feedback/30)))
Java
public static final String GET_BY_ID = "http://10.10.4.150:61511/api/Feedback/30";

EditText id;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    id = (EditText) findViewById(R.id.idtxt);
}
public void click(View v) {
    if (v.getId() == R.id.btnget) {
        insertData (id.getText().toString()) ;
    }

}
public void  insertData (String value){
    HashMap<String,String> param = new HashMap<String, String>();
    param.put("id",value);
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, GET_BY_ID,null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            Log.d("Response", response.toString());

            try {
                JSONObject ob = response.getJSONObject("userId")    ;
                int name = ob.getInt("userId");
                Toast.makeText(getBaseContext(),name,Toast.LENGTH_LONG).show();
            } catch (JSONException e) {
                e.printStackTrace();
                Toast.makeText(getBaseContext(),e.getMessage(),Toast.LENGTH_LONG).show();

            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(getBaseContext(),error.getMessage(),Toast.LENGTH_LONG).show();

        }

    }) {

        @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");
            headers.put("User-agent", "My useragent");
            return headers;
        }};

    RequestQueue requestQueue = Volley.newRequestQueue(this);
    requestQueue.add(request);
}
}


What I have tried:

i trying to connect my project in android studio to Asp.net API and i'm using Volley Lib to Get Json Request but he did'nt read the response and I getting this massage in Log ((( E/Volley: [352] BasicNetwork.performRequest: Unexpected response code 400 for http://10.10.4.150:61511/api/Feedback/30)))
Posted
Comments
Richard Deeming 25-Oct-18 11:48am    
Your API is returning error 400 - bad request.

You need to fix your request to match what your API is expecting.

We can't tell you how to do that, because we can't see your API.
Member 14032301 28-Oct-18 4:41am    
postman test api
https://pasteboard.co/HKw7Ydl.jpg
David Crow 30-Oct-18 10:05am    
What happens when you (single) step through the code using the debugger?
Member 14032301 1-Nov-18 5:03am    
get this massage in android studio dubugger
E/Volley: [352] BasicNetwork.performRequest: Unexpected response code 400 for http://10.10.4.150:61511/api/Feedback/30
David Crow 5-Nov-18 9:01am    
What happens if you open that URL (http://10.10.4.150:61511/api/Feedback/30) in a browser?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900