Konnte nicht finden, was mit meinem req-Objekt nicht stimmt. Ich habe diesen Fehler erhalten, als ich versuchte, Push-Benachrichtigungen im Callback zu senden. Versucht, meine Anfrage Daten mit jslint.com zu verknüpfen, nichts falsch damit. Habe dafür stundenlang den Kopf gekratzt!Ungültiger JSON im Anfragetext mit ionischen Push
{ "link": null, "message": "Ungültige JSON anfordern Körper Für leere JSON- Pass '{}'.", "Type": "UnprocessableEntity"}
mein Code wie folgt:
var title = req.body.title,
message = req.body.message;
// Define relevant info
var ionic_api_token = 'eyJ0eXAiOTdGb-xQVQaD2sV7qTh7XNKCnwiJKV1QiLJhbGciOiJIUzI1NiJ9.eyJqdGkiOiI2MjiNC03YjE5LTQ3MzMtYjJhMy0zM2Y3MjBkYzU4MjcifQ.s3e6pCwlVUBAs8kvbO';
var device_tokens = ['d44pDarVamnNJS2cNJ2modyBxjZZxcHLlnhQN4wZkJdbgkOw96rq9EEv2WCA5MKU6do0pJoO5rsmQsBAecFt4OIFB0hhD4Dp2K-uMbjum828j-8LKtpCTtGoIDBUvYI6L'];
var ionic_security_profile = 'main';
// Build the request object
var req = {
method: 'POST',
url: 'https://api.ionic.io/push/notifications',
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + ionic_api_token
},
data: {
"tokens": device_tokens,
"profile": ionic_security_profile,
"notification": {
"title": title,
"message": message,
"android": {
"title": title,
"message": message
},
"ios": {
"title": title,
"message": message
}
}
}
};
function callback(error, response, body) {
console.log(body)
}
request(req, callback);
});
ist es etwas mit der Antwort zu tun? Könnten Sie die Antwort json von Ihrer Netzwerkkonsole aus teilen? –
@Nannakuhtum ich bereits geteilt. Hier ist die vollständige Antwort: '{" meta ": {" status ": 422," version ":" 2.0.0-beta.0 "," request_id ":" 28ac473b-ea54-4e7a-bd69- "}," error ": {" link ": null," message ":" Ungültiger JSON im Anfragetext. Bei leerem JSON passiere '{}'. "," type ":" UnprocessableEntity "}} ' –
escape 'title' und 'Botschaft'. Ich füge auch eine Antwort hinzu .. –