(.NET Core C#) HTTP POST with Binary Data in Request Body
Do an HTTPS POST with a binary request body. Note: This example requires Chilkat v11.0.0 or greater.
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Chilkat.Http http = new Chilkat.Http();
Chilkat.FileAccess fac = new Chilkat.FileAccess();
byte[] reqBody = null;
reqBody = fac.ReadEntireFile("qa_data/pdf/helloWorld.pdf");
Chilkat.HttpResponse resp = new Chilkat.HttpResponse();
success = http.HttpBinary("POST","https://example.com/something",reqBody,"application/pdf",resp);
if (success == false) {
Debug.WriteLine(http.LastErrorText);
return;
}
int responseStatusCode = resp.StatusCode;
Debug.WriteLine("Status code: " + Convert.ToString(responseStatusCode));
// For example, if the response is XML, JSON, HTML, etc.
Debug.WriteLine("response body:");
Debug.WriteLine(resp.BodyStr);
|