HTTP request with trailer

Joined
Mar 22, 2024
Messages
1
Reaction score
0
I'm writing an http request that requires the use of http trailer, i've searched around a bit but didn't find any example using plain java 8 (no spring or servlets).

This is the method i've currently written:

public WebResponse uploadFileSend(String URL, String httpMethod, String pdfPath, String secret, String hash256) throws IOException {
byte[] pdfContent = Files.readAllBytes(Paths.get(pdfPath));

String requestUrl = new StringBuilder()
.append(URL)
.toString();

URL url = new URL(requestUrl);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setDoOutput(true);
conn.setInstanceFollowRedirects(false);
conn.setChunkedStreamingMode(-1);
conn.setRequestMethod(httpMethod.toUpperCase());
conn.setRequestProperty("x-api-key", apiKey);
conn.setRequestProperty("Content-Type", "application/pdf");
conn.setRequestProperty("x-amz-meta-secret", secret);
conn.setRequestProperty("transfer-encoding", "chunked");
conn.setRequestProperty("Trailer", "x-amz-checksum-sha256");
conn.setRequestProperty("charset", "utf-8");
conn.setUseCaches(false);

DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.write(pdfContent);
wr.flush();
wr.close();

BufferedReader bf = new BufferedReader(new InputStreamReader(conn.getInputStream()));
StringBuilder response = new StringBuilder();
String line;

while ((line = bf.readLine()) != null) {
response.append(line);
}

return new WebResponse(conn.getResponseCode(), conn.getHeaderField("x-amz-version-id"));
}

I'm not sure how to proceed from here to actually send the trailer in the request.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,057
Messages
2,570,443
Members
47,113
Latest member
XZJMike318

Latest Threads

Top