POST 요청시 JSON을 사용하는 jax-rs 및 jersey를 사용하여 REST 웹 서비스를 만들었습니다. 내 웹 서비스 클래스는 다음과 같습니다REST 웹 서비스 반환 415 - 지원되지 않는 미디어 유형
@Path("/webhookservice")
public class Webhook {
@POST
@Consumes(MediaType.APPLICATION_JSON)
public Response readData (Song song) {
// Prints out the song info
System.out.println("SONG INFO \n=======================");
System.out.println("songname: " + song.getSongname());
System.out.println("artist: " + song.getArtist());
// Repsonse with a HTTP 200 OK
Response response = Response.status(200).build();
return response;
}
}
내 노래 클래스 :
public class Song {
private String songname;
private String artist;
public String getSongname() { return this.songname; }
public String getArtist() { return this.artist; }
public void setSongname (String songname) { this.songname = songname; }
public void setArtist (String artist) { this.artist = artist; }
}
내 web.xml을 (필요한 경우)
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<servlet>
<servlet-name>SnapScan-Webhook</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>za.co.lancet.service</param-value>
</init-param>
<init-param>
<param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
<param-value>true</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SnapScan-Webhook</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
내가 RESTClient 조금 사용하고, 잘 , 휴식 고객 ... 여기에 내가 보내는 내용의 스크린 샷이 있습니다.
내가 보내면 415 지원되지 않는 미디어 유형 오류가 발생합니다. 왜 그런 생각이 들지?
클라이언트가 'Content-Type : application/json' 헤더를 보내고 있습니까? – lefloh
당신은 당신이 옳을 수도있는 것을 압니다. 나를 보자. – Tiwaz89
@lefloh - 너는 승자 야! 당신 말이 옳았는데, 나는이 작은 클라이언트 응용 프로그램에서 설정해야한다는 것을 알지조차 모릅니다. 답변으로 게시 할 수 있으며 동의 할 것입니다. 감사! – Tiwaz89