Java
Java
HTTP POST with Binary Data in Request Body
See more HTTP Examples
Do an HTTPS POST with a binary request body.Chilkat Java Downloads
import com.chilkatsoft.*;
public class ChilkatExample {
static {
try {
System.loadLibrary("chilkat");
} catch (UnsatisfiedLinkError e) {
System.err.println("Native code library failed to load.\n" + e);
System.exit(1);
}
}
public static void main(String argv[])
{
boolean success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttp http = new CkHttp();
CkFileAccess fac = new CkFileAccess();
CkByteData reqBody = new CkByteData();
success = fac.ReadEntireFile("qa_data/pdf/helloWorld.pdf",reqBody);
CkHttpResponse resp = new CkHttpResponse();
success = http.HttpBinary("POST","https://example.com/something",reqBody,"application/pdf",resp);
if (success == false) {
System.out.println(http.lastErrorText());
return;
}
int responseStatusCode = resp.get_StatusCode();
System.out.println("Status code: " + responseStatusCode);
// For example, if the response is XML, JSON, HTML, etc.
System.out.println("response body:");
System.out.println(resp.bodyStr());
}
}