I am executing a POST request to a server, which responds "properly", but when trying to call the mergeFromString()
function I receive the following error:
Google\Protobuf\Internal\GPBDecodeException: Error occurred during parsing: Unexpected wire type. in Google\Protobuf\Internal\Message.php on line 353
I am using CURL with PHP:
$handle = curl_init($url);
$curl_options = [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $body,
CURLOPT_HEADER => true,
CURLOPT_VERBOSE => true
];
curl_setopt_array($handle, $curl_options);
$curlResponse = curl_exec($handle);
$responseMessage = new MyMessage();
$responseMessage->mergeFromString($curlResponse);
curl_close($handle);
The result of var_dump($curlResponse)
is as follows:
╔╔eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjI1MTQwMTAsInVzZXJuYW1lIjoiNTM1MTAyODA2MCIsInZlcnNpb24iOiIyMTgwNiJ9.Li-bp3bIPdIrsRhuTWEWToS0ds62VCG-a2PCGaKSrigڲօ═"
In plain text it should look something like this:
1: 1
2: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MjI1MTQwMTAsInVzZXJuYW1lIjoiNTM1MTAyODA2MCIsInZlcnNpb24iOiIyMTgwNiJ9.Li-bp3bIPdIrsRhuTWEWToS0ds62VCG-a2PCGaKSrig
3: 1619765852
My .proto file for the response is as follows:
message MyMessage{
// I'm only interested in property 2
string prop = 2;
}
Environment:
"protobuf-php / protobuf": "^ 0.1.3",
"google / protobuf": "^ 3.16"
However, tests using Protoman (A Postman-like API client for protobuf-based messages) are successful. I did the tests with the same proto files that I use in PHP.