Sample code for 30+ languages & platforms
Go

HTTP POST with Binary Data in Request Body

See more HTTP Examples

Do an HTTPS POST with a binary request body.

Chilkat Go Downloads

Go
    success := false

    // This example assumes the Chilkat API to have been previously unlocked.
    // See Global Unlock Sample for sample code.

    http := chilkat.NewHttp()

    fac := chilkat.NewFileAccess()

    var reqBody []byte
    reqBody = fac.ReadEntireFile("qa_data/pdf/helloWorld.pdf")

    resp := 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()