Попытка отправить JSON-объект через мой сайт через nodeJS - Запрос.
var options = {
uri: 'http://localhost/test.php',
method: 'POST',
json: {
"longUrl": "http://www.google.com/"
}
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
});
В моем скрипте test.php я просто пишу переменные $ _REQUEST через json_encode в файле отладки:
<?php
file_put_contents('test.debug.txt', "TEST: " . json_encode($_REQUEST) . json_encode($_POST));
Очевидно, что $ _POST ничего не содержит.Для первого шага отладки я записал параметры в своем URL, чтобы проверить, работает ли PHP Script:
var options = {
uri: 'http://localhost/test.php?debug=1',
method: 'POST',
json: {
"longUrl": "http://www.google.com/"
}
};
request(options, function (error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body)
}
});
И этот дополнительный debug=1
сделал его таким образом, чтобы я мог видеть {'debug':1} как вывод в моем файле отладки.Итак, мой вопрос прямо сейчас: что случилось с переменными POST?
Вывод из запроса NodeJS:
0|server | request:
0|server | Request {
0|server | _events:
0|server | [Object: null prototype] {
0|server | error: [Function: bound ],
0|server | complete: [Function: bound ],
0|server | pipe: [Function],
0|server | data: [Function],
0|server | end: [Function] },
0|server | _eventsCount: 5,
0|server | _maxListeners: undefined,
0|server | method: 'POST',
0|server | body:
0|server | '{"longUrl":""http://www.google.com/"}',