2012-04-05 5 views
0

Ich versuche, eine Post-Anfrage an Parse senden: https://parse.com/docs/rest#objects-creating. Kann nicht richtig funktionieren. Ich benutze die API-ID für App und Rest in meinem Programm.Post Request zum Analysieren Mobile Datenverwaltung

var https = require('https'); 

var options = { 
host: 'api.parse.com', 
port: 443, 
path: '/1/classes/GameScore', 
method: 'POST', 
headers: { 
    X-Parse-Application-Id: "", 
    X-Parse-REST-API-Key: "", 
    Content-Type: "application/json"; 
} 
data: { 
    "score": 1337, "playerName": "Sean Plott", "cheatMode": false 
} 
} 

}; 

var req = https.request(options, function(res) { 
console.log("statusCode: ", res.statusCode); 
console.log("headers: ", res.headers); 

res.on('data', function(d) { 
process.stdout.write(d); 
}); 
}); 
req.end(); 

req.on('error', function(e) { 
console.error(e); 
}); 

EDITED: hinzugefügt Fehlerreaktion:

SyntaxError: Unexpected token - 
at Module._compile (module.js:406:25) 
at Object..js (module.js:417:10) 
at Module.load (module.js:343:31) 
at Function._load (module.js:302:12) 
at Array.<anonymous> (module.js:430:10) 
at EventEmitter._tickCallback (node.js:126:26) 
+0

Es wäre schön, von Ihnen sein, wenn Sie auch die Antwort hinzufügen || Fehler, dass Sie dieses Programm ausführen? das wird helfen. – Futur

+0

Die Fehlerantwort wurde hinzugefügt. – mnort9

+0

Fehlt Ihnen ein Teil der Fehlerausgabe? Ich sehe keinen Hinweis auf eine Zeile in Ihrem (JavaScript-) Code. –

Antwort

1

Sie können nicht - als Schlüssel für das Objekt ohne Anführungszeichen verwenden.

So müssen Sie

headers: { 
    X-Parse-Application-Id: "", 
    X-Parse-REST-API-Key: "", 
    Content-Type: "application/json"; 
} 

ändern

headers: { 
    "X-Parse-Application-Id": "", 
    "X-Parse-REST-API-Key": "", 
    "Content-Type": "application/json"; 
}