0
我發現自己在一個情況下,我需要在我的服務器上獲取一些POST數據,並做一些簡單的事情。但是當我嘗試用www.hurl.it網站進行測試時,它總是說415 Unsupported Media Type。澤西REST問題與消費JSON
這是我的JSON我發送:
{
"pictures": {
"picture": [
{
"id": "1",
"name": "10_aut_linen_male_less_student_work_yellow_n_cold.png"
},
{
"id": "2",
"name": "10_aut_linen_male_less_student_work_yellow_n_mild.png"
},
{
"id": "3",
"name": "10_aut_linen_male_less_student_work_yellow_n_hot.png"
}
]
}
}
這是模型類:
package com.models.sm7;
import java.util.ArrayList;
import java.util.List;
public class Sm7Pictures {
private Pictures pictures;
public Pictures getPictures() {
return pictures;
}
public void setPictures(Pictures pictures) {
this.pictures = pictures;
}
public class Pictures {
private List<Picture> picture = new ArrayList<Picture>();
public List<Picture> getPicture() {
return picture;
}
public void setPicture(List<Picture> picture) {
this.picture = picture;
}
}
public class Picture {
private String id;
private String name;
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
這是我的服務類:
@Path("sm7Service")
public class Sm7Service {
Sm7DAO sm7DAO = new Sm7DAO();
@GET
@Path("/testSm7")
@Produces(MediaType.TEXT_PLAIN)
public String testSm(){
return "Hello";}
@POST
@Path("/checkPictures")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.TEXT_PLAIN)
public String getPictures(Sm7Pictures picture){
System.out.println("pokrenuto");
return "Hello";}
}
的DAO類在那裏我會盡我所有的邏輯,但爲了測試紫袍,我只是把文本放在了純淨的地方......我真的把我的頭撞過來了是:S,因爲它很簡單,但我無法讓它工作。我敢打賭,這與模型課有關係嗎?請幫忙!