(Go) 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.
success := false
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
http := Http_Ref.html">chilkat.NewHttp()
fac := FileAccess_Ref.html">chilkat.NewFileAccess()
var reqBody []byte
reqBody = fac.ReadEntireFile("qa_data/pdf/helloWorld.pdf")
resp := HttpResponse_Ref.html">chilkat.NewHttpResponse()
success = http.HttpBinary("POST","https://example.com/something",reqBody,"application/pdf",resp)
if success == false {
fmt.Println(http.LastErrorText())
http.DisposeHttp()
fac.DisposeFileAccess()
resp.DisposeHttpResponse()
return
}
responseStatusCode := resp.StatusCode()
fmt.Println("Status code: ", responseStatusCode)
// For example, if the response is XML, JSON, HTML, etc.
fmt.Println("response body:")
fmt.Println(resp.BodyStr())
http.DisposeHttp()
fac.DisposeFileAccess()
resp.DisposeHttpResponse()
|