如何在android中使用原始json发送post请求

如何在android中使用原始json发送post请求,android,post,http-post,retrofit,android-volley,Android,Post,Http Post,Retrofit,Android Volley,我无法发送原始post请求并从服务器接收响应 公共作废登录(){ RequestQueue RequestQueue=Volley.newRequestQueue(this); 字符串URL=”https://api-test01.moneyboxapp.com/users/login"; 最后一个字符串requestBody=“{\”Email\:\”androidtest@moneyboxapp.com\“,”密码\“:\”P455word12\“,”Idfa\“:”任何东西\“}”; St

我无法发送原始post请求并从服务器接收响应

公共作废登录(){
RequestQueue RequestQueue=Volley.newRequestQueue(this);
字符串URL=”https://api-test01.moneyboxapp.com/users/login";
最后一个字符串requestBody=“{\”Email\:\”androidtest@moneyboxapp.com\“,”密码\“:\”P455word12\“,”Idfa\“:”任何东西\“}”;
StringRequest StringRequest=new StringRequest(Request.Method.POST,URL,new Response.Listener()){
@凌驾
公共void onResponse(字符串响应){
Log.i(“截击”,回应);
}
},new Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
Log.e(“截击”,error.toString());
}
}) {
@凌驾
公共字符串getBodyContentType(){
返回“application/json;charset=utf-8”;
}
@凌驾
公共字节[]getBody()抛出AuthFailureError{
试一试{
return requestBody==null?null:requestBody.getBytes(“utf-8”);
}捕获(不支持的编码异常uee){
wtf(“尝试使用%s获取%s的字节时不支持编码”,请求体,“utf-8”);
返回null;
}
}
@凌驾
公共映射getHeaders()引发AuthFailureError{
Map params=新的HashMap();
参数put(“AppId”、“3a97b932a9d449c981b595”);
参数put(“内容类型”、“应用程序/json”);
参数put(“应用版本”、“5.10.0”);
参数put(“apiVersion”、“3.0.0”);
返回参数;
}
@凌驾
受保护的响应parseNetworkResponse(NetworkResponse响应){
字符串responseString=“”;
if(响应!=null){
responseString=String.valueOf(response.statusCode);
//可以获取更多详细信息,如response.headers
}
返回Response.success(responseString,HttpHeaderParser.parseCacheHeaders(Response));
}
};
添加(stringRequest);

这个问题看起来可能包含敏感信息。考虑编辑或删除你的问题。
public void login() {

       RequestQueue requestQueue = Volley.newRequestQueue(this);
       String URL = "https://api-test01.moneyboxapp.com/users/login";

       final String requestBody = "{\"Email\":\"androidtest@moneyboxapp.com\",\"Password\":\"P455word12\",\"Idfa\":\"ANYTHING\"}";

       StringRequest stringRequest = new StringRequest(Request.Method.POST, URL, new Response.Listener<String>() {
           @Override
           public void onResponse(String response) {
               Log.i("VOLLEY", response);
           }
       }, new Response.ErrorListener() {
           @Override
           public void onErrorResponse(VolleyError error) {
               Log.e("VOLLEY", error.toString());
           }
       }) {
           @Override
           public String getBodyContentType() {
               return "application/json; charset=utf-8";
           }

           @Override
           public byte[] getBody() throws AuthFailureError {
               try {
                   return requestBody == null ? null : requestBody.getBytes("utf-8");
               } catch (UnsupportedEncodingException uee) {
                   VolleyLog.wtf("Unsupported Encoding while trying to get the bytes of %s using %s", requestBody, "utf-8");
                   return null;
               }
           }

           @Override
           public Map<String, String> getHeaders() throws AuthFailureError {
               Map<String, String>  params = new HashMap<String, String>();
               params.put("AppId", "3a97b932a9d449c981b595");
               params.put("Content-Type", "application/json");
               params.put("appVersion","5.10.0");
               params.put("apiVersion","3.0.0");

               return params;
           }
           @Override
           protected Response<String> parseNetworkResponse(NetworkResponse response) {
               String responseString = "";
               if (response != null) {
                   responseString = String.valueOf(response.statusCode);
                   // can get more details such as response.headers
               }
               return Response.success(responseString, HttpHeaderParser.parseCacheHeaders(response));
           }
       };

       requestQueue.add(stringRequest);