我正在尝试从 android 调用球衣服务
@POST
@Path("/share")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
public Response shareProgramVideo(@FormParam("from")Integer from, @FormParam("to")List<Integer> to,@FormParam("programIds")List<Integer> programIds)
该服务适用于 html 表单
<html>
<head>
<title>REST with Forms</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<br />
<form method="post" action="../dataService/rest/secure/program/share">
from: <input type="text" name="from" id="from" /><br />
to 1: <input type="text" name="to" id="to" /><br />
to 2: <input type="text" name="to" id="to" /><br />
programIds 1: <input type="text" name="programIds" id="programIds" /><br />
programIds 2: <input type="text" name="programIds" id="programIds" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
我正在使用 android 和 HttpRequest 库(https://github.com/kevinsawicki/http-request),但它给了我 400 bad request 错误
List<Integer> programs = new ArrayList<Integer>();
programs.add(1);
programs.add(2);
List<Integer> to = new ArrayList<Integer>();
to.add(1);
to.add(2);
Map<String, Object> data = new HashMap<String, Object>();
data.put("from", 1);
data.put("to", to);
data.put("programIds", programs);
HttpRequest request = HttpRequest.post(url)
.basic(WebServiceConfig.ADMIN, WebServiceConfig.ADMIN_PSW).contentType("application/x-www-form-urlencoded")
.acceptJson().form(data);
if (request.created() || request.ok()) {
return true;
} else {
Log.e("CreateUserProgramTask",
"request.code()=" + request.code() + "request.body()="
+ request.body());
return false;
}