java rest post 参数_Java REST API:POST方法获取NULL参数

我从我的android应用程序发送参数到后端,并试图检索我的POST客户端在我的POST方法中发送的参数,但我仍然收到空参数,即使客户端发送非空的参数。Java REST API:POST方法获取NULL参数

的Java POST方法:

@POST

@Produces({ "application/json" })

@Path("/login")

public LoginResponse Login(@FormParam("email") String email, @FormParam("password") String password) {

LoginResponse response = new LoginResponse();

if(email != null && password != null && email.length() != 0 && password.length() != 0){

//Detect if null or empty

//Code

}

return response;

}

Android客户端:

HttpClient httpclient = new DefaultHttpClient();

HttpPost httppost = new HttpPost("http://MY_APP_NAME.appspot.com/user/login");

String json = "";

JSONObject jsonObject = new JSONObject();

try {

jsonObject.accumulate("email", "[email protected]");

jsonObject.accumulate("password", "123");

json = jsonObject.toString();

StringEntity se = new StringEntity(json);

httppost.setEntity(se);

httppost.setHeader("Content-Type", "application/json");

httppost.setHeader("ACCEPT", "application/json");

HttpResponse httpResponse = httpclient.execute(httppost);

}

catch(Exception ex) { }

相信方法的Content-Type和客户是一样的好。为什么我没有从Java后端方法接收参数?

检验:

的网址是否正确,连接是否正常

由应用程序发送的参数不是空

2016-04-03

Dinuka

+0

在你的Java客户端中检查了'LoginResponse'吗? 使用[发贴人](https://chrome.google.com/webstore/detail/postman/fhbjgbiflinjbdggehcddcbncdddomop?hl=en),并将您的参数传递给相同的邮件类型的网址,让我们知道您获得了什么? 我认为在后端你不会返回任何东西 –

+0

当我发送身体数据为x-www-form-urlencoded时,我正在返回数据并且它在postman中运行良好。不知道为什么。我没有在这个问题中加入这个问题,因为它是无关紧要的。无论如何编辑它。问题是,我得到后端方法中的空参数@Kathi –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值