Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C++) Azure Create Storage AccountDemonstrates how to create an Azure storage account.
#include <CkHttpW.h> #include <CkJsonObjectW.h> #include <CkHttpResponseW.h> void ChilkatSample(void) { // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttpW http; // Load an OAuth2 access token previously fetched by this example: Get Azure OAuth2 Access Token CkJsonObjectW jsonToken; bool success = jsonToken.LoadFile(L"qa_data/tokens/azureToken.json"); // Assuming success.. http.put_AuthToken(jsonToken.stringOf(L"access_token")); wprintf(L"AuthToken: %s\n",http.authToken()); http.put_Accept(L"application/json"); // Create the following JSON: // { // "sku": { // "name": "Standard_GRS" // }, // "kind": "StorageV2", // "location": "eastus2", // } // Use this online tool to generate the code from sample JSON: // Generate Code to Create JSON CkJsonObjectW jsonRequestBody; jsonRequestBody.UpdateString(L"sku.name",L"Standard_GRS"); jsonRequestBody.UpdateString(L"kind",L"StorageV2"); jsonRequestBody.UpdateString(L"location",L"eastus2"); const wchar_t *url = L"https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Storage/storageAccounts/{accountName}?api-version=2018-02-01"; CkHttpResponseW *resp = http.PText(L"PUT",url,jsonRequestBody.emit(),L"utf-8",L"application/json",false,false); if (http.get_LastMethodSuccess() != true) { wprintf(L"%s\n",http.lastErrorText()); return; } wprintf(L"Response Status Code: %d\n",resp->get_StatusCode()); CkJsonObjectW json; json.Load(resp->bodyStr()); json.put_EmitCompact(false); wprintf(L"%s\n",json.emit()); if (resp->get_StatusCode() >= 300) { wprintf(L"Failed.\n"); delete resp; return; } // Successful requests to create a new account return a 202 status code with an empty response body. The storage account is created asynchronously. // If the account already exists or is being provisioned, the request response has a 200 return code with the configuration of the existing storage account in the response body. if (resp->get_StatusCode() == 202) { wprintf(L"Azure-AsyncOperation: %s\n",resp->getHeaderField(L"Azure-AsyncOperation")); } if (resp->get_StatusCode() == 200) { // Parse a response like this: // { // "sku": { // "name": "Standard_GRS", // "tier": "Standard" // }, // "kind": "StorageV2", // "id": "/subscriptions/6c42643b-ebef-45f0-b917-b3583b84a57f/resourceGroups/gChilkat/providers/Microsoft.Storage/storageAccounts/chilkatsoftware", // "name": "chilkatsoftware", // "type": "Microsoft.Storage/storageAccounts", // "location": "eastus2", // "tags": {}, // "properties": { // "networkAcls": { // "bypass": "AzureServices", // "virtualNetworkRules": [ // ], // "ipRules": [ // ], // "defaultAction": "Allow" // }, // "supportsHttpsTrafficOnly": false, // "encryption": { // "services": { // "file": { // "enabled": true, // "lastEnabledTime": "2019-05-14T22:18:33.2246670Z" // }, // "blob": { // "enabled": true, // "lastEnabledTime": "2019-05-14T22:18:33.2246670Z" // } // }, // "keySource": "Microsoft.Storage" // }, // "accessTier": "Hot", // "provisioningState": "Succeeded", // // "creationTime": "2019-05-14T22:18:33.1309165Z", // "primaryEndpoints": { // "dfs": "https://chilkatsoftware.dfs.core.windows.net/", // "web": "https://chilkatsoftware.z20.web.core.windows.net/", // "blob": "https://chilkatsoftware.blob.core.windows.net/", // "queue": "https://chilkatsoftware.queue.core.windows.net/", // "table": "https://chilkatsoftware.table.core.windows.net/", // "file": "https://chilkatsoftware.file.core.windows.net/" // }, // "primaryLocation": "eastus2", // "statusOfPrimary": "available", // "secondaryLocation": "centralus", // "statusOfSecondary": "available" // } // } // Use this online tool to generate parsing code from sample JSON: // Generate Parsing Code from JSON const wchar_t *skuName = 0; const wchar_t *skuTier = 0; const wchar_t *kind = 0; const wchar_t *id = 0; const wchar_t *name = 0; const wchar_t *v_type = 0; const wchar_t *location = 0; const wchar_t *propertiesNetworkAclsBypass = 0; const wchar_t *propertiesNetworkAclsDefaultAction = 0; bool propertiesSupportsHttpsTrafficOnly; bool propertiesEncryptionServicesFileEnabled; const wchar_t *propertiesEncryptionServicesFileLastEnabledTime = 0; bool propertiesEncryptionServicesBlobEnabled; const wchar_t *propertiesEncryptionServicesBlobLastEnabledTime = 0; const wchar_t *propertiesEncryptionKeySource = 0; const wchar_t *propertiesAccessTier = 0; const wchar_t *propertiesProvisioningState = 0; const wchar_t *propertiesCreationTime = 0; const wchar_t *propertiesPrimaryEndpointsDfs = 0; const wchar_t *propertiesPrimaryEndpointsWeb = 0; const wchar_t *propertiesPrimaryEndpointsBlob = 0; const wchar_t *propertiesPrimaryEndpointsQueue = 0; const wchar_t *propertiesPrimaryEndpointsTable = 0; const wchar_t *propertiesPrimaryEndpointsFile = 0; const wchar_t *propertiesPrimaryLocation = 0; const wchar_t *propertiesStatusOfPrimary = 0; const wchar_t *propertiesSecondaryLocation = 0; const wchar_t *propertiesStatusOfSecondary = 0; int i; int count_i; skuName = json.stringOf(L"sku.name"); skuTier = json.stringOf(L"sku.tier"); kind = json.stringOf(L"kind"); id = json.stringOf(L"id"); name = json.stringOf(L"name"); v_type = json.stringOf(L"type"); location = json.stringOf(L"location"); propertiesNetworkAclsBypass = json.stringOf(L"properties.networkAcls.bypass"); propertiesNetworkAclsDefaultAction = json.stringOf(L"properties.networkAcls.defaultAction"); propertiesSupportsHttpsTrafficOnly = json.BoolOf(L"properties.supportsHttpsTrafficOnly"); propertiesEncryptionServicesFileEnabled = json.BoolOf(L"properties.encryption.services.file.enabled"); propertiesEncryptionServicesFileLastEnabledTime = json.stringOf(L"properties.encryption.services.file.lastEnabledTime"); propertiesEncryptionServicesBlobEnabled = json.BoolOf(L"properties.encryption.services.blob.enabled"); propertiesEncryptionServicesBlobLastEnabledTime = json.stringOf(L"properties.encryption.services.blob.lastEnabledTime"); propertiesEncryptionKeySource = json.stringOf(L"properties.encryption.keySource"); propertiesAccessTier = json.stringOf(L"properties.accessTier"); propertiesProvisioningState = json.stringOf(L"properties.provisioningState"); propertiesCreationTime = json.stringOf(L"properties.creationTime"); propertiesPrimaryEndpointsDfs = json.stringOf(L"properties.primaryEndpoints.dfs"); propertiesPrimaryEndpointsWeb = json.stringOf(L"properties.primaryEndpoints.web"); propertiesPrimaryEndpointsBlob = json.stringOf(L"properties.primaryEndpoints.blob"); propertiesPrimaryEndpointsQueue = json.stringOf(L"properties.primaryEndpoints.queue"); propertiesPrimaryEndpointsTable = json.stringOf(L"properties.primaryEndpoints.table"); propertiesPrimaryEndpointsFile = json.stringOf(L"properties.primaryEndpoints.file"); propertiesPrimaryLocation = json.stringOf(L"properties.primaryLocation"); propertiesStatusOfPrimary = json.stringOf(L"properties.statusOfPrimary"); propertiesSecondaryLocation = json.stringOf(L"properties.secondaryLocation"); propertiesStatusOfSecondary = json.stringOf(L"properties.statusOfSecondary"); } wprintf(L"Success.\n"); delete resp; } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.