HTTP状态415 - RESTEASY001055:无法使用内容类型

时间:2017-07-18 20:46:48

标签: java rest

我正在尝试上传图片(例如tiff,用PDF扫描)。我在SoapUI中做了一个项目并且图片发送正确,遗憾的是我的java代码错误...收到' HTTP状态415 - RESTEASY001055:无法使用内容类型'消息。图像作为blob存储在数据库中。 对于代码200,我应该得到json

private void sendRequestToRestService(byte[] imgageBlob) throws IOException {
String user = "testUser";
String password = "testPass";
String restServiceAddressToUpload = //The address of the service on which I want to send the file;
String authData = user + ":" + password;
Tika tika = new Tika();
String mimetype = tika.detect(imgageBlob);

String auth = user + ":" + password;
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("ISO-8859-1")));
String authHeader = "Basic " + new String(encodedAuth);

//  ByteArrayEntity entity = new ByteArrayEntity(imgageBlob);

Client client = ClientBuilder.newClient();
Response res = client.target(restServiceAddressToUpload)
        .request(MediaType.MULTIPART_FORM_DATA)
        .header(HttpHeaders.AUTHORIZATION, authHeader)
        .post(Entity.entity(imgageBlob, mimetype));

if (res.getStatus() == 200) {
    String readEntity = res.readEntity(String.class);
    // ...
} else {
    String readEntity = res.readEntity(String.class);
    // ...
}

}

1 个答案:

答案 0 :(得分:0)

您需要添加Content-Type标题