我正在使用REST在eclipse中創建一個非常簡單的cordova
混合移動項目演示。我的想法是,我註冊了詳細信息,當我提交登錄按鈕時,它會調用REST URL並保存登錄信息。科爾多瓦如何將POST數據發佈到REST URL
問題是得到HTTP Status 415 – Unsupported Media Type
。
的index.html
是:
<form name="login" id="register" action="http://localhost:8080/peerby/user/" method="post">
<label for="fname">First Name</label>
<input id="fname" name="firstName" placeholder="First Name" type="text"/>
<br>
<label for="lname">Last Name</label>
<input id="lname" name="lastName" placeholder="Last Name" type="text"/>
<br>
<label for="adr">Address</label>
<input id="adr" name="address" placeholder="Address" type="text"/>
<br>
<label for="eml">Email</label>
<input id="eml" name="email" placeholder="Email" type="email"/>
<br>
<label for="pswd">Password</label>
<input id="pswd" name="pasword" placeholder="password" type="password"/>
<br>
<input type="submit" value="Login" id="log"/>
</form>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
這是userResorce
文件:
@Path("user")
@Produces(MediaType.APPLICATION_JSON)
public class UserResource {
private UserDAO userDao = new UserDAO();
@GET
public List<UserModel> getAllUsers() {
return userDao.getAllUserDao();
}
@GET
@Path("/{userID}")
public UserModel getUser(@PathParam("userID") Long id) {
return userDao.getUserDao(id);
}
@POST
@Consumes(MediaType.TEXT_HTML) //used several mediaType
public List<UserModel> saveUser(UserModel user) {
userDao.addUserDao(user);
return userDao.getAllUserDao();
}
}
使用Postman
它工作正常。但使用cordova
,我得到Unsupported Media Type
。我使用了幾個MediaType
作爲@Consumes
。但我得到的是Unsupported Media Type
。
我已經設置了'enctype ='application/json''和'@Consumes(MediaType.APPLICATION_JSON)',但沒有改變。我得到了'不支持的媒體類型' – nSv23
您是否調試過您在控制器上接收的格式? – YuVi
你的意思是psotman?我使用json進行POST和GET。我可以使用GET在cordova模擬器上顯示出問題。但我無法發佈到其他網址。 – nSv23