Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/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 用谷歌截击发送请求参数_Android_Spring Mvc_Android Volley - Fatal编程技术网

Android 用谷歌截击发送请求参数

Android 用谷歌截击发送请求参数,android,spring-mvc,android-volley,Android,Spring Mvc,Android Volley,我正在尝试使用截击从android手机向Spring上编写的HTTP服务器发出GET请求 我提出了一个自定义请求,它扩展了request并覆盖了它的getParams()metod: @Override protected Map<String, String> getParams() throws AuthFailureError { Map<String, String> parameters = new HashMap<>();

我正在尝试使用截击从android手机向Spring上编写的HTTP服务器发出GET请求

我提出了一个自定义请求,它扩展了
request
并覆盖了它的
getParams()
metod:

@Override
protected Map<String, String> getParams() throws AuthFailureError {
        Map<String, String> parameters = new HashMap<>();
        parameters.put("email", "xxxx@xxx.com");
        parameters.put("password", "xxxx");    
        return parameters;
}
@覆盖
受保护的映射getParams()引发AuthFailureError{
映射参数=新的HashMap();
参数。放置(“电子邮件”xxxx@xxx.com");
参数。输入(“密码”、“xxxx”);
返回参数;
}
我以这种方式提出我的请求:

GsonRequest = new GsonRequest<String>(Request.Method.GET, "http://192.168.43.15:10000/login",
                new Response.Listener<String>() {
                    @Override
                    public void onResponse(String response) {
                        ....
                    }
                },
                new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError error) {
                        ......
                    }
        });
Log.i(TAG, new String(request.getBody()));
requestQueue.add(request);
GsonRequest=新的GsonRequest(Request.Method.GET,”http://192.168.43.15:10000/login",
新的Response.Listener(){
@凌驾
公共void onResponse(字符串响应){
....
}
},
新的Response.ErrorListener(){
@凌驾
公共无效onErrorResponse(截击错误){
......
}
});
Log.i(标记,新字符串(request.getBody());
添加(请求);
日志显示请求具有以下参数:

电子邮件=xxxx%40xxx.com和密码=xxxx&

但有一个错误:

的意外响应代码400

看起来请求参数没有发送


这是我的服务器代码:

@RequestMapping(path = "/login", method = RequestMethod.GET)
public ResponseEntity<String> login(@RequestParam(name = "email") String email,
                                    @RequestParam(name = "password") String password) {
  User user = repository.findByEmailAndPassword(email, password);
    if (user != null) {
        return new ResponseEntity("Found", HttpStatus.OK);
    }

    return new ResponseEntity<>("Not found", HttpStatus.OK);
}
@RequestMapping(path=“/login”,method=RequestMethod.GET)
公共响应登录(@RequestParam(name=“email”)字符串电子邮件,
@RequestParam(name=“password”)字符串密码{
User User=repository.findByEmailAndPassword(电子邮件,密码);
如果(用户!=null){
返回新的响应属性(“找到”,HttpStatus.OK);
}
返回新的响应属性(“未找到”,HttpStatus.OK);
}
我认为我的android设备上的代码有问题,因为当我从浏览器发出请求时,一切都正常


有人能告诉我问题出在哪里吗?

经过一番查找,我找到了这篇文章,其中解释了为什么不发送参数


您可以使用StringRequest而不是JSONRequest,因为您返回的是字符串响应。看起来您想向服务器发送一些数据,但您使用的是GET方法,请使用POST方法尝试,当数据库未接收到必需的参数时,会出现错误。