I am transferring data from a C++ client to a nodejs server.
I compress the string using zlib deflate first, then I use curl_easy_escape to url encode the compressed string.
std::string s = zlib_compress(temp.str());
std::cout << s <<"\n";
CURL *handle = curl_easy_init();
char* o = curl_easy_escape(handle, s.data(), s.size());
std::cout << o <<"\n";
Then I send it using:
std::string bin(o);
curl_easy_setopt(handle, CURLOPT_POSTFIELDSIZE, bin.size());
curl_easy_setopt(handle, CURLOPT_POSTFIELDS, bin.data());
curl_easy_perform(handle);
When I run this, I get the output:
x??с??Ҵ4?
x%DA%D3%D1%81%80%E2%92%D2%B44%1D%03%00%1BW%03%E5
Now, I receive the second encoded string on my nodejs server as it is. I now try to decode it.
var x = req.params;
for (var key in req.body)
{
console.log(key);
var x = unescape(key);
var buffer = new Buffer(x);
console.log(x);
zlib.inflate(buffer, function(err, buffer) {
console.log(err+" here");
});
}
Which outputs:
x%DA%D3%D1%81%80%E2%92%D2%B44%1D%03%00%1BW%03%E5
xÚÓÑâÒ´4å
Error: incorrect header check here
What is the problem here? How do I debug it?