Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Im facing some problem to send volley post request to pass json from android app to java restful service the Error occure: " Basic Network Unexpected response code 415" the snaps of my code is here. If anyone know solution please help.



@POST
@Path("/feedback")
@Consumes(MediaType.APPLICATION_JSON)
public void postFeedback(feedbackModel fbkModel){

f_name = fbkModel.getName();
f_mobile = fbkModel.getMobile().toString();
f_description = fbkModel.getDescription();
f_rating = fbkModel.getRating();


dataService.insertFeedback(f_name, f_mobile, f_description, f_rating);
}

// Android app method to make json and passing on web service...

Java
private void createJsonObj(){
  String url = "http://192.168.23.1:8080/RESTfulExample/rest/file/feedback";
      showProgressDialog();

      StringRequest stringRequest = new StringRequest(Request.Method.POST,
      url,
      new Response.Listener<String>() {

      @Override
      public void onResponse(String response) {
      Log.d(TAG, response.toString());
      //msgResponse.setText(response.toString());
                          Toast.makeText(getBaseContext(),response.toString(),Toast.LENGTH_LONG).show();
      hideProgressDialog();
      }
      }, new Response.ErrorListener() {

      @Override
      public void onErrorResponse(VolleyError error) {
      VolleyLog.d(TAG, "Error: " + error.getMessage());
      hideProgressDialog();

      NetworkResponse networkResponse = error.networkResponse;
      if (networkResponse != null) {
  Log.e("Volley", "Error. HTTP Status Code:"+networkResponse.statusCode);
      }

      if (error instanceof TimeoutError) {
      Log.e("Volley", "TimeoutError");
      }else if(error instanceof NoConnectionError){
      Log.e("Volley", "NoConnectionError");
      } else if (error instanceof AuthFailureError) {
      Log.e("Volley", "AuthFailureError");
      } else if (error instanceof ServerError) {
      Log.e("Volley", "ServerError");
      } else if (error instanceof NetworkError) {
      Log.e("Volley", "NetworkError");
      } else if (error instanceof ParseError) {
      Log.e("Volley", "ParseError");
      }

      }
      }) {


      //   * Passing some request headers


      @Override
      protected Map<String, String> getParams() throws AuthFailureError{
      Map<String, String> params = new HashMap<String, String>();
      params.put("name", f_name);
      params.put("mobile", f_mobile);
      params.put("description", f_description);
      params.put("rating",f_ratVel );

      return params;
      }

      @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;
      }


      };

      requestQueue.add(stringRequest);

      }
Posted

1 solution

See http://www.restapitutorial.com/httpstatuscodes.html[^] for an explanation of error code 415.
 
Share this answer
 

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