Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) Azure ServiceBus - Request a Token from ACSThis example duplicates the HTTP POST described at Request a Token from ACS.
#include <CkHttp.h> #include <CkHttpRequest.h> #include <CkHttpResponse.h> void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat HTTP API to have been previously unlocked. // See Global Unlock Sample for sample code. // The goal of this example is to send the following HTTP POST: // POST https://your-namespace-sb.accesscontrol.windows.net/WRAPv0.9/ HTTP/1.1 // Content-Type: application/x-www-form-urlencoded // Host: your-namespace-sb.accesscontrol.windows.net // Content-Length: 136 // Expect: 100-continue // Connection: Keep-Alive // // wrap_name=owner&wrap_password=r8LuxCKD6DWY8auQcFql4M7euH2UuhcLcV1TaJTqNNE%3d&wrap_scope=http%3a%2f%2fyour-namespace.servicebus.windows.net%2f // CkHttp http; CkHttpRequest req; // Build the HTTP request... req.put_HttpVerb("POST"); req.put_Path("/WRAPv0.9/"); req.put_ContentType("application/x-www-form-urlencoded"); // Adding the Connection: Keep-Alive is optional. It only makes sense if the intent is to send // additional requests to the same domain (your-namespace-sb.accesscontrol.windows.net) within a reasonable time period. req.AddHeader("Connection","Keep-Alive"); // The Expect: 100-continue really isn't necessary. This only makes sense when a response is large. The "100-continue" // provides a means for the HTTP server to alert the HTTP client that the request failed before sending the full response. // In this case, the response size is small, so there's no real need to bother with an "Expect: 100-continue". // If desired, it would be added just like any request header: req.AddHeader("Expect","100-continue"); // Note: The following headers are automatically added by Chilkat: Content-Type, Host, Content-Length. // The application should NOT set these directly. // Add the query parameters // When URL decoded and split, the query params look like this: // // wrap_name=owner // wrap_password=r8LuxCKD6DWY8auQcFql4M7euH2UuhcLcV1TaJTqNNE= // wrap_scope=http://your-namespace.servicebus.windows.net/ // Pass the URL-decoded values to AddParam. req.AddParam("wrap_name","owner"); req.AddParam("wrap_password","r8LuxCKD6DWY8auQcFql4M7euH2UuhcLcV1TaJTqNNE="); req.AddParam("wrap_scope","http://your-namespace.servicebus.windows.net/"); // OK.. our request is properly setup. Now send to the web server at your-namespace-sb.accesscontrol.windows.net. // We want https (i.e. SSL/TLS), so the port would be 443. bool useTls = true; CkHttpResponse *resp = http.SynchronousRequest("your-namespace-sb.accesscontrol.windows.net",443,useTls,req); if (http.get_LastMethodSuccess() != true) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // A successful response will have a status code = 200. if (resp->get_StatusCode() != 200) { strOut.append("Response Status Code = "); strOut.appendInt(resp->get_StatusCode()); strOut.append("\r\n"); strOut.append(resp->bodyStr()); strOut.append("\r\n"); strOut.append("Failed."); strOut.append("\r\n"); delete resp; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } // A successful response will contain a URL encoded param string such as the following: // wrap_access_token=net.windows.servicebus.action%3d // Listen%252cManage%252cSend%26 // http%253a%252f%252fschemas.microsoft.com%252faccesscontrolservice%252f2010%252f07%252fclaims%252fidentityprovider%3d // https%253a%252f%252fyour-namespace-sb.accesscontrol.windows.net%252f%26 // Audience%3dhttp%253a%252f%252fyour-namespace.servicebus.windows.net%252f%26 // ExpiresOn%3d1404435127%26 // Issuer%3dhttps%253a%252f%252fyour-namespace-sb.accesscontrol.windows.net%252f%26 // HMACSHA256%3dF%252bBoXUoifWdT%252fly8Oic9V1oPBbc3KmXKbSJbVhGSopU%253d& // wrap_access_token_expires_in=10799 // // The UrlEncParamValue method can be used to extract individual param values by name. // There are two params in the response: wrap_access_token and wrap_access_token_expires. // (It's a bit confusing because the value of the wrap_access_token is itself a URL encoded // param string.) // Get the access token from the response: const char *accessToken = resp->urlEncParamValue(resp->bodyStr(),"wrap_access_token"); strOut.append("Your access token is the following param string:"); strOut.append("\r\n"); strOut.append(accessToken); strOut.append("\r\n"); delete resp; SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.