스프링 웹 서비스를 사용하여 이미지를 보내는 동안 문제가 발생했습니다.스프링에서 웹 서비스에서 이미지를 보내는 방법
@Controller
public class WebService {
@RequestMapping(value = "/image", headers = "Accept=image/jpeg, image/jpg, image/png, image/gif", method = RequestMethod.GET)
public @ResponseBody byte[] getImage() {
try {
InputStream inputStream = this.getClass().getResourceAsStream("myimage.jpg");
BufferedImage bufferedImage = ImageIO.read(inputStream);
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
ImageIO.write(bufferedImage , "jpg", byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}
@ResponseBody
아래와 같이
I 작성한 JSON 제어기로 응답으로 변환한다.
웹 서비스를 테스트하기 위해 RestClient를 사용하고 있습니다.
하지만 내가 http://localhost:8080/my-war-name/rest/image
URL로 타격을 가할 때.
Header
Accept=image/jpg
나는 실패 창-1252 인코딩을 사용하여 문자열을 위해 RESTClient
응답 본체의 변환에 다음과 같은 오류에 직면. 응답 본문이 설정되지 않았습니다! 내가 이
헤더가 너무 오류가 예상 추가되지 않습니다
HTTP Status 405 - Request method 'GET' not supported type Status report message Request method 'GET' not supported description The specified HTTP method is not allowed for the requested resource (Request method 'GET' not supported).는 또한
하면 오류 아래에 직면 (이 나를 인도 해주십시오) 브라우저 크롬과 파이어 폭스 을 사용하고
이 요청으로 식별 된 리소스는 특성이 허용되지 않는 응답을 생성하는 만 가능합니다. accordi 요청에 겨 나는 http://krams915.blogspot.com/2011/02/spring-3-rest-web-service-provider-and.html 자습서를 따랐다()
헤더를 "동의 함".
내 requirment는 Android 클라이언트로 이미지를 바이트 형식으로 전송하는 것입니다.
[스프링 MVC : @ResponseBody의 이미지를 반환하는 방법] (http://stackoverflow.com/questions/5690228/spring-mvc-how-to-turnurn-image-in-responsebody) – skaffman