I am using curl in c to send POST and GET requests. I have a custom callback for the responses.
static size_t callback(void *data, size_t size, size_t nmemb, void *userp)
{
printf("This is the data:\n%s\n", data);
jobj = json_tokener_parse(data);
return size * nmemb;
}
However when I print the data, an extra 0 is appended. The first response I get:
{
"success": true,
"message": "You are now logged in as Tour Driver",
"data": {
"token": "137|jzGCVhGaaaNmsshAo29MktQZ9XMWXcxUpZw0jPUj",
"user": {
"id": "8cdbef45-fd36-4d29-8742-7fe537aabb57",
"name": "Tour Driver",
"roles": [
"driver"
],
"role": "driver",
"profile_photo_url": "https:\/\/ui-avatars.com\/api\/?name=T+D&color=7F9CF5&background=EBF4FF",
"teams": [
{
"id": "9bc3xh6d-ca2d-4af3-8f26-99376effa488",
"name": "XAD IT",
"membership": {
"user_id": "8cdbef45-fd36-4d29-8742-7fe537aabb57",
"team_id": "9bc3xh6d-ca2d-4af3-8f26-99376effa488",
"role": "driver",
"created_at": "2022-08-30T06:31:18.000000Z",
"updated_at": "2022-08-30T06:32:36.000000Z"
}
}
]
}
}
}
0
Not sure why it is adding the zero at the end, but it can still be parsed to a JSON message.
However, when I try to do a GET request after that, the response is:
{
"success":true,
"message":"Found 1 trips",
"data":[
{
"id":"8d030886-bf23-40b4-a6ab-5ae93a6c6f3a",
"legId":null,
"departureTime":"2022-09-14 13:34:00",
"estimatedDepartureTime":null,
"arrivalTime":"2022-09-14 13:46:00",
"estimatedArrivalTime":null,
"travelerReferenceNumbers":[
],
"distance":6315,
"customer":{
"id":"e156cfa5-7a0f-4707-8294-695ae4f58a57",
"email":"empty@test.com",
"birthDate":null,
"phones":[
]
},
"from":{
"id":"94adb642-295c-456e-b019-edb6a8c77ec4",
"name":null,
"stop_reference_id":null,
"stationId":null,
"coordinate_id":"c581c9cd-0b04-4c9e-b695-552f4f8a10d0",
"address_id":"a72f3071-84b1-4c7d-afc7-2552d29d40e8",
"extraInfo":null,
"coordinates":{
"id":"c581c9cd-0b04-4c9e-b695-552f4f8a10d0",
"lng":5.895355,
"lat":51.959115
},
"physical_address":{
"id":"a72f3071-84b1-4c7d-afc7-2552d29d40e8",
"street":null,
"houseNumber":null,
"houseNumberAddition":null,
"addressAdditionalInfo":null,
"postalCode":null
}
},
"to":{
"id":"0eefc767-ac7a-49f5-917d-e519a959fd7b",
"name":null,
"stop_reference_id":null,
"stationId":null,
"coordinate_id":"1abc25cb-27be-47bd-8951-ade611fa01dc",
"address_id":"3341b1ec-7215-4cab-8684-8f436a0801a9",
"extraInfo":null,
"coordinates":{
"id":"1abc25cb-27be-47bd-8951-ade611fa01dc",
"lng":5.942919,
"lat":51.987601
},
"physical_address":{
"id":"3341b1ec-7215-4cab-8684-8f436a0801a9",
"street":null,
"houseNumber":null,
"houseNumberAddition":null,
"addressAdditionalInfo":null,
"postalCode":null
}
},
"asset_type":null,
"asset":null,
"pricing":null,
"suboperator":null,
"state":{
"id":"38d02ace-324d-46c2-9f36-f7fb5dd55999",
"state":"NOT_STARTED"
}
}
]
1
}
0
Because of the 1 at the bottom, it is not parsable into a JSON message.
Whenever I don't add my own callback (but instead, let curl handle the callback) there is no 0 at the end.
I can't seem to figure out why the 0 and 1 are added to the message. Especially the 1, because it makes the JSON message invalid.
Any ideas?