Hi,

I'm struggling to understand what the issue might be, but I'm getting this
error:

{"error-code":"Internal Error","error-message":"JSON parse error:
Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not
recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser);
nested exception is com.fasterxml.jackson.core.JsonParseException:
Unexpected character ('/' (code 47)): maybe a (non-standard) comment? (not
recognized as one since Feature 'ALLOW_COMMENTS' not enabled for parser)\n
at [Source: (PushbackInputStream); line: 1, column: 2]","request-id":""}

When I
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, s2 );

But for some reason, the error does not occur when I use
curl_easy_setopt( curl, CURLOPT_POSTFIELDS, s1 );

But BOTH strings are nul-terminated and contain the exact same data:

Contents of string: *(s1)* 123 34 104 111 115 116 34 58 34 49 57 50 46 49
54 56 46 49 57 53 46 49 50 34 125

Contents of string: *(s2)* 123 34 104 111 115 116 34 58 34 49 57 50 46 49
54 56 46 49 57 53 46 49 50 34 125
What am I not understanding here? The strings are single-byte characters,
so might it be a problem with some internal unicode-conversion?

Here is the complete code:

void dumpstring( const char * p ) {

std::cerr << EOL;

std::cerr << "Contents of string:" EOL;

for ( ; *p; p++ ) {

std::cout << (int)*p << " ";

}

std::cerr << EOL;

}

bool ExecuteCommand( const char * token, const char * nodename, const char *
command, const char * tenant, const cmd_params & params ) {

CURL * curl;
CURLcode res;

curl = curl_easy_init();

if ( curl ) {

curl_easy_setopt( curl, CURLOPT_URL, ( ( (std::string)"
https://ubihub.cityiq-dvp.io/"; + tenant + "/v1.0/ecs/command/" ) + nodename
+ "\?commandId=" + command + "&mode=sync" ).c_str() );
curl_easy_setopt( curl, CURLOPT_FOLLOWLOCATION, 1L );

struct curl_slist * headers = NULL;
headers = curl_slist_append( headers, ( ( (std::string)"Authorization:
Bearer " ) + token ).c_str() );

if ( params.size() ) {

headers = curl_slist_append( headers, "Content-Type: application/json");

Json::StreamWriterBuilder builder;
builder["indentation"] = "";

Json::Value values;

for ( size_t u = 0; u < params.size(); u++ ) {

std::size_t equalpos = params.at( u ).find( "=" );

if ( std::string::npos != equalpos ) {

std::string key = params.at( u ).substr( 0, equalpos );
std::string value = params.at( u ).substr( equalpos + 1 );

values[key] = value;

}


}

std::string serialized = Json::writeString( builder, values );

const char * s1 = "{\"host\":\"192.168.195.12\"}";
const char * s2 = serialized.c_str();

dumpstring( s1 );
dumpstring( s2 );

curl_easy_setopt( curl, CURLOPT_POSTFIELDS, s2 );

}

curl_easy_setopt( curl, CURLOPT_HTTPHEADER, headers );

curl_easy_setopt( curl, CURLOPT_CUSTOMREQUEST, "POST" );

res = curl_easy_perform( curl );

curl_easy_cleanup( curl );

if( CURLE_OK != res ) {

std::cerr << "curl_easy_perform() failed: " << curl_easy_strerror( res ) <<
EOL;
return false;

}

}

return true;

}

As I wrote above, both potential strings are dumped at runtime and both
contain the same characters.

Any help is appreciated.
Thanks
-- 
Unsubscribe: https://lists.haxx.se/listinfo/curl-library
Etiquette:   https://curl.haxx.se/mail/etiquette.html

Reply via email to