C++ REST GET does not return data

Fred Young 1 Reputation point
2022-03-25T11:27:13.26+00:00

Using C++ and Visual Studio 2022, cpr REST GET is not returning data. Status code is 0 but data not returned. The server log shows the GET operated correctly on the server. The URL, when tested from a command prompt with "curl" returns the data, but the C++ program using cpr does not.

string rest_get(string url)
{
ofstream CrnActLog;
CrnActLog.open("..\CrnAct.log", ofstream::out | ofstream::app);
CrnActLog << GetTimeNow() << "- " <<"Initiating GET call to " << url << endl;

Response r = cpr::Get(Url{ url.c_str() },
        Authentication{ "restService", "rest@pf" },
        Parameters{ {"anon", "true"}, {"key", "value"} });

CrnActLog << GetTimeNow() << "- " << "r.status_code  " << r.status_code << endl;
CrnActLog << GetTimeNow() << "- " << "r.header[content-type]  " << r.header["content-type"] << endl;
CrnActLog << GetTimeNow() << "- " << "r.text  " << r.text << endl;

r.status_code;                  // 200
r.header["content-type"];       // application/json; charset=utf-8
r.text;                         // JSON text string

Json::Value root;

int page = root["page"].asInt();
Json::Value total = root["total"];
Json::Value data = root["data"];

CrnActLog << GetTimeNow() << "- " <<"rest_call returned " << r.text << endl;
CrnActLog.close();
return r.text;

}

C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,637 questions
Microsoft Partner Center API
Microsoft Partner Center API
Microsoft Partner Center: A Microsoft website for partners that provides access to product support, a partner community, and other partner services.API: A software intermediary that allows two applications to interact with each other.
329 questions
{count} votes