我正在尝试通过在 Tomcat 7 上运行 Apache Jersey REST 的 Windows Server 2008 R2 上的 cURL 命令行执行以下命令。
curl -X POST -d "<userList xmlns="urn:user"><user role="ROLE_OPERATOR" loginName="test_login1"></user></userList>" -H "Content-Type: application/xml" --basic --user username:password http://localhost:8080/meolutws/UserList/
当我发出命令时,我收到带有消息的 HTTP 400:“客户端发送的请求在语法上不正确”。
Web 服务上的方法签名如下所示:
@POST
@CONSUMES({"application/xml"})
public Response createUsers(UserList users){
}
UserList 类定义如下:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "UserList", namespace = "urn:user", propOrder = {
"users"
})
@XmlRootElement(name = "userList", namespace = "urn:user")
public class UserList
implements Serializable
{
@XmlElement(name = "user")
protected List<User> users;
public List<User> getUsers() {
if (users == null) {
users = new ArrayList<User>();
}
return this.users;
}
}
用户定义如下:
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "User", namespace = "urn:user")
@XmlRootElement(name = "user", namespace = "urn:user")
public class User
implements Serializable
{
@XmlAttribute(name = "loginName", required = true)
protected String loginName;
@XmlAttribute(name = "role", required = true)
protected String role;
public String getLoginName() {
return loginName;
}
public void setLoginName(String value) {
this.loginName = value;
}
public String getRole() {
return role;
}
public void setRole(String value) {
this.role = value;
}
}
我错过了什么?