1
要求工作正常,如果我的網址發送給它需要的屬性作爲第一個參數,但要發送的選項對象,其中包含請求參數時,每次都失敗屬性:Node.js的請求返回錯誤:連接ECONNREFUSED時設置選項參數
"use strict"
var https = require('https'),
request = require('request');
var obj = {
translate: function(textToTranslate) {
var options = {
url: "https://translate.yandex.net/api/v1.5/tr.json/translate",
qs: {
key: process.env.TRANSLATION_APP_TOKEN,
lang: "en-ru",
text: textToTranslate
}
}, translationRequest = https.request(options, function(response) {
response.on('data', function (chunk) {
console.log(JSON.parse(chunk).text[0]);
});
});
console.log(options);
translationRequest.on('error', function (response) {
console.log(response);
});
translationRequest.end();
}
};
obj.translate("hello");
我使用qs選項來傳遞參數,但嘗試過formData和body,但它不工作。
感謝您的幫助