Unicode C++
Unicode C++
MercadoLibre - Create Test User
See more MercadoLibre Examples
Crea un usuario de testChilkat Unicode C++ Downloads
#include <CkHttpW.h>
#include <CkJsonObjectW.h>
#include <CkHttpResponseW.h>
#include <CkStringBuilderW.h>
void ChilkatSample(void)
{
bool success = false;
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
CkHttpW http;
// First get our previously obtained OAuth2 access token.
CkJsonObjectW jsonToken;
success = jsonToken.LoadFile(L"qa_data/tokens/mercadolibre.json");
// Implements the following CURL command:
// curl -X POST -H "Content-Type: application/json" -d
// '{
// "site_id":"MLA"
// }'
// https://api.mercadolibre.com/users/test_user?access_token=MY_ACCESS_TOKEN
// Use the following online tool to generate HTTP code from a CURL command
// Convert a cURL Command to HTTP Source Code
// Use this online tool to generate code from sample JSON:
// Generate Code to Create JSON
// The following JSON is sent in the request body.
// {
// "site_id": "MLA"
// }
CkJsonObjectW json;
json.UpdateString(L"site_id",L"MLA");
http.SetRequestHeader(L"Content-Type",L"application/json");
http.SetUrlVar(L"access_token",jsonToken.stringOf(L"access_token"));
CkHttpResponseW resp;
success = http.HttpJson(L"POST",L"https://api.mercadolibre.com/users/test_user?access_token={$access_token}",json,L"application/json",resp);
if (success == false) {
wprintf(L"%s\n",http.lastErrorText());
return;
}
CkStringBuilderW sbResponseBody;
resp.GetBodySb(sbResponseBody);
CkJsonObjectW jResp;
jResp.LoadSb(sbResponseBody);
jResp.put_EmitCompact(false);
wprintf(L"Response Body:\n");
wprintf(L"%s\n",jResp.emit());
// A response status code of 201 indicates success.
int respStatusCode = resp.get_StatusCode();
wprintf(L"Response Status Code = %d\n",respStatusCode);
if (respStatusCode >= 400) {
wprintf(L"Response Header:\n");
wprintf(L"%s\n",resp.header());
wprintf(L"Failed.\n");
return;
}
// Sample JSON response:
// (Sample code for parsing the JSON response is shown below)
// {
// "id": 577815702,
// "nickname": "TETE5320415",
// "password": "qatest4890",
// "site_status": "active",
// "email": "test_user_80450945@testuser.com"
// }
// Sample code for parsing the JSON response...
// Use the following online tool to generate parsing code from sample JSON:
// Generate Parsing Code from JSON
// Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat.
// See this example explaining how this memory should be used: const char * functions.
int id = jResp.IntOf(L"id");
const wchar_t *nickname = jResp.stringOf(L"nickname");
const wchar_t *password = jResp.stringOf(L"password");
const wchar_t *site_status = jResp.stringOf(L"site_status");
}