Android 截击:[213]基本网络。性能请求:意外响应代码415

Android 截击:[213]基本网络。性能请求:意外响应代码415,android,json,rest,android-volley,Android,Json,Rest,Android Volley,我使用Restful Java在android中使用POST方法和凌空截击解析数据json。当我尝试从Advanced REST Client插入数据时,它将数据插入db success,但在Android中,当我插入数据并看到它发生异常时,如下所示: 我的宁静(更新了): } 我的活动课: private static final String URL_BOOK = "http://192.168.1.221:9999/bookticket_service/bookticket/jso

我使用Restful Java在android中使用POST方法和凌空截击解析数据json。当我尝试从Advanced REST Client插入数据时,它将数据插入db success,但在Android中,当我插入数据并看到它发生异常时,如下所示:

我的宁静(更新了):

}

我的活动课:

    private static final String URL_BOOK = "http://192.168.1.221:9999/bookticket_service/bookticket/json";

    EditText fullname, birthday, address;

    fullname = (EditText) findViewById(R.id.fullname);
    birthday = (EditText) findViewById(R.id.birthday);
    address = (EditText) findViewById(R.id.address);
    btnBook = (Button) findViewById(R.id.btnBook);
    requestQueue = Volley.newRequestQueue(getApplicationContext());

    btnBook.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            StringRequest request = new StringRequest(Request.Method.POST, URL_BOOK, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    System.out.println(response.toString());
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("Error: " + error.getMessage());

                    Toast.makeText(getApplicationContext(),
                            error.getMessage(), Toast.LENGTH_LONG).show();                        
                }
            }){
               @Override
                protected Map<String,String> getParams() throws AuthFailureError {
                   Map<String, String> parameter = new HashMap<String, String>();
                   parameter.put("Content-Type", "application/json; charset=utf-8");
                   parameter.put("fullname", fullname.getText().toString());
                   parameter.put("birthday", birthday.getText().toString());
                   parameter.put("address", address.getText().toString());
                   return parameter;
               }
            };
            // volley saves the response in its cache and this behavior may cause some strange problem
            // request.setShouldCache(false);
            requestQueue.add(request);
        }
    });

如何修复异常,感谢您的帮助

StringRequest
默认生成
x-www-form-urlencoded
请求。。。将
内容类型
放入由
getParams()生成的参数中
未更改it@KhanhLuongVan您使用的web api是哪种语言,如php或。net@KhanhLuongVan,该异常非常明显,如果列不可为空,则必须插入记录尝试使用
getBody
而不是
getParams
,请阅读我的答案,当然你可以忽略那里的
parseNetworkResponse
。另一种方式,您可以使用
JsonObjectRequest
而不是
StringRequest
@BNK:谢谢,根据您的回答,我已经解决了我的问题:)
StringRequest
默认生成
x-www-form-urlencoded
请求。。。将
内容类型
放入由
getParams()生成的参数中
未更改it@KhanhLuongVan您使用的web api是哪种语言,如php或。net@KhanhLuongVan,该异常非常明显,如果列不可为空,则必须插入记录尝试使用
getBody
而不是
getParams
,请阅读我的答案,当然你可以忽略那里的
parseNetworkResponse
。另一种方式,您可以使用
JsonObjectRequest
而不是
StringRequest
。@BNK:谢谢,根据您的回答,我已经解决了我的问题:)
    private static final String URL_BOOK = "http://192.168.1.221:9999/bookticket_service/bookticket/json";

    EditText fullname, birthday, address;

    fullname = (EditText) findViewById(R.id.fullname);
    birthday = (EditText) findViewById(R.id.birthday);
    address = (EditText) findViewById(R.id.address);
    btnBook = (Button) findViewById(R.id.btnBook);
    requestQueue = Volley.newRequestQueue(getApplicationContext());

    btnBook.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            StringRequest request = new StringRequest(Request.Method.POST, URL_BOOK, new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    System.out.println(response.toString());
                }
            }, new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    VolleyLog.d("Error: " + error.getMessage());

                    Toast.makeText(getApplicationContext(),
                            error.getMessage(), Toast.LENGTH_LONG).show();                        
                }
            }){
               @Override
                protected Map<String,String> getParams() throws AuthFailureError {
                   Map<String, String> parameter = new HashMap<String, String>();
                   parameter.put("Content-Type", "application/json; charset=utf-8");
                   parameter.put("fullname", fullname.getText().toString());
                   parameter.put("birthday", birthday.getText().toString());
                   parameter.put("address", address.getText().toString());
                   return parameter;
               }
            };
            // volley saves the response in its cache and this behavior may cause some strange problem
            // request.setShouldCache(false);
            requestQueue.add(request);
        }
    });
com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: 
Column 'fullname' cannot be null