Unicode C
Unicode C
Example: Http.SetOAuthRsaKey method
Demonstrates theSetOAuthRsaKey method.
Chilkat Unicode C Downloads
#include <C_CkPfxW.h>
#include <C_CkPrivateKeyW.h>
#include <C_CkHttpW.h>
#include <C_CkHttpResponseW.h>
void ChilkatSample(void)
{
BOOL success;
HCkPfxW pfx;
HCkPrivateKeyW privKey;
HCkHttpW http;
HCkHttpResponseW resp;
success = FALSE;
pfx = CkPfxW_Create();
success = CkPfxW_LoadPfxFile(pfx,L"qa_data/pfx/MCD_Sandbox_chilkat_iccp_API_Keys/chilkat_iccp-sandbox.p12",L"keystorepassword");
if (success == FALSE) {
wprintf(L"%s\n",CkPfxW_lastErrorText(pfx));
CkPfxW_Dispose(pfx);
return;
}
privKey = CkPrivateKeyW_Create();
success = CkPfxW_PrivateKeyAt(pfx,0,privKey);
if (success == FALSE) {
wprintf(L"%s\n",CkPfxW_lastErrorText(pfx));
CkPfxW_Dispose(pfx);
CkPrivateKeyW_Dispose(privKey);
return;
}
http = CkHttpW_Create();
// Use OAuth1.0a authentication.
CkHttpW_putOAuth1(http,TRUE);
// Use your own consumer key (this is not a valid consumer key)
CkHttpW_putOAuthConsumerKey(http,L"123abc");
CkHttpW_putOAuthSigMethod(http,L"RSA-SHA256");
success = CkHttpW_SetOAuthRsaKey(http,privKey);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkPfxW_Dispose(pfx);
CkPrivateKeyW_Dispose(privKey);
CkHttpW_Dispose(http);
return;
}
// Tell Chilkat to automatically calculate and add the oauth_body_hash field when sending the request.
CkHttpW_putOAuthBodyHash(http,TRUE);
// 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.
resp = CkHttpResponseW_Create();
success = CkHttpW_HttpStr(http,L"POST",L"https://chilkatsoft.com/echo_request_body.asp",L"<notUsed>123</notUsed>",L"utf-8",L"application/xml",resp);
if (success == FALSE) {
wprintf(L"%s\n",CkHttpW_lastErrorText(http));
CkPfxW_Dispose(pfx);
CkPrivateKeyW_Dispose(privKey);
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
return;
}
// Examine the request header we just sent..
wprintf(L"%s\n",CkHttpW_lastHeader(http));
// 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="*****"
CkPfxW_Dispose(pfx);
CkPrivateKeyW_Dispose(privKey);
CkHttpW_Dispose(http);
CkHttpResponseW_Dispose(resp);
}