post.setHeader("Authorization", getAuthHeader(user, password));
post.setEntity(entity);
try {
HttpResponse response = client.execute(post);
if (response.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_CREATED) {
throw new ZendeskApiException("Upload of attachment failed\n" + response.getStatusLine().getStatusCode() + " " + response.getStatusLine().getReasonPhrase());
}
BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
StringBuilder sb = new StringBuilder();
String line = "";
while ((line = rd.readLine()) != null) {
sb.append(line);
}
UploadResult uploadResult = JsonHelper.unmarshal(sb.toString(), UploadResult.class);
return uploadResult.getUpload();
} catch (Exception e) {
throw new ZendeskApiException(e);
}
}