Chilkat2-Python
Chilkat2-Python
HTTP POST with Binary Data in Request Body
See more HTTP Examples
Do an HTTPS POST with a binary request body.Chilkat Chilkat2-Python Downloads
import sys
import chilkat2
success = False
# This example assumes the Chilkat API to have been previously unlocked.
# See Global Unlock Sample for sample code.
http = chilkat2.Http()
fac = chilkat2.FileAccess()
# reqBody is a memoryview
reqBody = fac.ReadEntireFile("qa_data/pdf/helloWorld.pdf")
resp = chilkat2.HttpResponse()
success = http.HttpBinary("POST","https://example.com/something",reqBody,"application/pdf",resp)
if (success == False):
print(http.LastErrorText)
sys.exit()
responseStatusCode = resp.StatusCode
print("Status code: " + str(responseStatusCode))
# For example, if the response is XML, JSON, HTML, etc.
print("response body:")
print(resp.BodyStr)