Sample code for 30+ languages & platforms
PowerBuilder

Example: Http.SetOAuthRsaKey method

Demonstrates the SetOAuthRsaKey method.

Chilkat PowerBuilder Downloads

PowerBuilder
integer li_rc
integer li_Success
oleobject loo_Pfx
oleobject loo_PrivKey
oleobject loo_Http
oleobject loo_Resp

li_Success = 0

loo_Pfx = create oleobject
li_rc = loo_Pfx.ConnectToNewObject("Chilkat.Pfx")
if li_rc < 0 then
    destroy loo_Pfx
    MessageBox("Error","Connecting to COM object failed")
    return
end if
li_Success = loo_Pfx.LoadPfxFile("qa_data/pfx/MCD_Sandbox_chilkat_iccp_API_Keys/chilkat_iccp-sandbox.p12","keystorepassword")
if li_Success = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    return
end if

loo_PrivKey = create oleobject
li_rc = loo_PrivKey.ConnectToNewObject("Chilkat.PrivateKey")

li_Success = loo_Pfx.PrivateKeyAt(0,loo_PrivKey)
if li_Success = 0 then
    Write-Debug loo_Pfx.LastErrorText
    destroy loo_Pfx
    destroy loo_PrivKey
    return
end if

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")

// Use OAuth1.0a authentication.
loo_Http.OAuth1 = 1

// Use your own consumer key (this is not a valid consumer key)
loo_Http.OAuthConsumerKey = "123abc"

loo_Http.OAuthSigMethod = "RSA-SHA256"

li_Success = loo_Http.SetOAuthRsaKey(loo_PrivKey)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Pfx
    destroy loo_PrivKey
    destroy loo_Http
    return
end if

// Tell Chilkat to automatically calculate and add the oauth_body_hash field when sending the request.
loo_Http.OAuthBodyHash = 1

// Send this request to an endpoint at chilkatsoft.com.  The purpose of this example is to show
// how the OAuth1.0a Authorization header is computed and sent by Chilkat.
// The chilkatsoft.com site itself doesn't do OAuth1.  It's just ignoring the Authorization header.
loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpStr("POST","https://chilkatsoft.com/echo_request_body.asp","<notUsed>123</notUsed>","utf-8","application/xml",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Pfx
    destroy loo_PrivKey
    destroy loo_Http
    destroy loo_Resp
    return
end if

// Examine the request header we just sent..
Write-Debug loo_Http.LastHeader

// Sample output:

// POST /echo_request_body.asp HTTP/1.1
// Host: chilkatsoft.com
// Accept: */*
// Accept-Encoding: gzip
// Content-Type: application/xml
// Content-Length: 22
// Authorization: OAuth oauth_consumer_key="123abc", oauth_nonce="A2E91C3B53E0BD7FBF71F441336679E358DDCEEE", oauth_body_hash="a5kPTsDwUwmBjC0voNlAAvM6YoaRS5X7sTO49jl3/h8=", oauth_timestamp="1756324932", oauth_signature_method="RSA-SHA256", oauth_version="1.0", oauth_signature="*****"


destroy loo_Pfx
destroy loo_PrivKey
destroy loo_Http
destroy loo_Resp