本文介绍了意外的响应代码415的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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);

}



//制作json并传递网络服务的Android应用程序方法...






@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...

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);

      }

推荐答案


这篇关于意外的响应代码415的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-19 16:45