2015-02-05 3 views
0

Я разрабатываю для некоторых данных сообщения API над nodejs. У меня проблемы. если я отправляю данные по https, тогда php обрабатывает пустые данные. Кто-нибудь знает? Спасибо.nodejs post пустые данные через соединение ssl

a.js =>

//https unauth disable 
process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; 

var http = require('https'); 

var post_req = null, 
post_data = '{ "dataid":"81","userid":"29" }'; 

var post_options = { 
    hostname: 'www.domain.com', 
    port : '443', 
    path : '/get.php', 
    method : 'POST', 
    headers : { 
     'Content-Type': 'application/json;', 
     'Content-Length': post_data.length 
    } 
}; 

debugger; 
post_req = http.request(post_options, function (res) { 
//console.log('STATUS: ' + res.statusCode); 
//console.log('HEADERS: ' + JSON.stringify(res.headers)); 
    res.setEncoding('utf8'); 
    res.on('data', function (chunk) { 
     console.log('Response: ', chunk); 
    }); 
}); 

post_req.on('error', function(e) { 
    console.log('problem with request: ' + e.message); 
}); 

debugger; 
post_req.write(JSON.stringify(post_data)); 
debugger; 
post_req.end(); 

И это блок кода PHP.

get.php =>

print_r($_POST); 

ответ

0

я могу это исправить:), если вы хотите использовать запрос JSon просто изменить тип содержимого. Наслаждайтесь:)

process.env['NODE_TLS_REJECT_UNAUTHORIZED'] = '0'; 
var request = require('request'); 

// Set the headers 
var headers = { 
    'User-Agent':  'Super Agent/0.0.1', 
    'Content-Type':  'application/x-www-form-urlencoded' 
} 

// Configure the request 
var options = { 
    url: 'https://www.domain.com', 
    method: 'POST', 
    headers: headers, 
    form: {"dataid":"81","userid":"29" } 
} 

// Start the request 
request(options, function (error, response, body) { 
    if (!error && response.statusCode == 200) { 
     // Print out the response body 
     console.log(body) 
    } 
}) ` 
Смежные вопросы