Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android getBytes()UTF-8_Android_Bytearray_Gson - Fatal编程技术网

Android getBytes()UTF-8

Android getBytes()UTF-8,android,bytearray,gson,Android,Bytearray,Gson,我正在试着提出一个POST gson请求。。。我需要以字节数组的形式传递一个正文 在数组的最后一个文本视图中,它显示了/u0000。。。当它呼叫服务器时,服务器向我发送400 JSONObject jsonObjectUsuario = new JSONObject(); try { jsonObjectUsuario.put("nome", et_nome.getText().toString()); jsonObjectUsuario.put("cpf", et_cpf.g

我正在试着提出一个POST gson请求。。。我需要以字节数组的形式传递一个正文

在数组的最后一个文本视图中,它显示了/u0000。。。当它呼叫服务器时,服务器向我发送400

JSONObject jsonObjectUsuario = new JSONObject();

try {
    jsonObjectUsuario.put("nome", et_nome.getText().toString());
    jsonObjectUsuario.put("cpf", et_cpf.getText().toString());
    jsonObjectUsuario.put("email", et_email.getText().toString());
    jsonObjectUsuario.put("senha", et_password.getText().toString());
} catch (JSONException e) {
    e.printStackTrace();
}

UserRequestHelper.userRequest(
    Request.Method.POST,
    EndpointURL.POST_USUARIO,
    jsonObjectUsuario.toString().getBytes(), 
    new Response.Listener<Usuario>() {
        @Override
        public void onResponse(Usuario response) {
            Toast.makeText(
                getActivity(),
                "Cadastro realizado com sucesso!",
                Toast.LENGTH_SHORT).show();

            getActivity()
                .getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fragment_initial, new LoginFragment())
                .remove(new UsuarioFragment())
                .commit();
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Toast.makeText(
                getActivity(),
                "Erro ao realizar cadastro.", 
                Toast.LENGTH_SHORT)
           .show();
        }
    }
);
怎么了?有人给我举了一个Gson POST请求的例子吗

请帮帮我

getBody()未被调用或使用。getBody()未被调用或使用。
    public GsonRequest(int method, String url, Class<T> clazz, byte[] body,
                   Response.Listener<T> listener, Response.ErrorListener errorListener) {
    super(method, url, errorListener);
    this.clazz = clazz;
    this.body = body;
    this.listener = listener;
}
    public static void userRequest(int method, String url, byte[] body, Response.Listener<Usuario> listener, Response.ErrorListener errorListener){
    GsonRequest<Usuario> usuarioGsonRequest = new GsonRequest<>(method, url, Usuario.class, body, listener, errorListener);

    VolleySingleton.getsInstance().addToRequestQueue(usuarioGsonRequest);
}
@Override
public byte[] getBody() throws AuthFailureError {
    return body != null ? body : super.getBody();
}