I wanna implement the HTTP post from curl.
curl $CURL_OPTS -X POST --data-binary {} -s -K <(cat <<< "-u micromdm:$API_TOKEN") "$SERVER_URL/$endpoint"
The curl command above sends empty binary data.
I know how to send string data.
Sending string data
try {
CloseableHttpClient httpClient = null;
try {
httpClient = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Content-Type", "application/json;charset=utf-8");
httpPost.addHeader("Accept", "application/json;charset=utf-8");
httpPost.addHeader("Authorization", "XXXXXXXX");
StringEntity se = new StringEntity(jsonstring, "UTF-8");
httpPost.setEntity(se);
HttpResponse httpResponse = httpClient.execute(httpPost);
catch () {
}
catch () {
}
But how to send empty binary data?
Trying
ByteArrayEntity byteArrayEntity = [];
httpPost.setEntity(byteArrayEntity, ContentType.DEFAULT_BINARY);
It is not work.
I read some articles which are not properly solutions.
http-post-in-java-with-file-upload
how-to-get-raw-binary-data-from-a-post-request-processed-by-spring
uploading-binary-data-with-httppost
There are many similar related articles, but I didn't find the solution. Can anyone give me the code sample for this? Thank you.