我已经在Raspberry Pi运行Express上建立了Node.Js网站。
我想使用动态DNS从Node.JS / Express更新我的Google DNS域
我尝试过的事情:
Management Assistant
使用curl命令看起来像这样:
function domainUpdate() {
console.log(`[SERVER] Posting to Google's Servers...`)
let username = process.env.USERNAME || ``;
let password = process.env.PASSWORD || ``;
let hostname = process.env.HOSTNAME || ``;
let url = `https://${username}:${password}@domains.google.com/nic/update?hostname=${hostname}`;
https.request(url, (res) => {
console.log(`status - ${res.statusCode}`);
console.log(`output - ${res.complete}`)
}).on("error", (e) => {
if (e) throw e
})
除了“ [SERVER]正在发布到Google的服务器...”之外没有任何输出
答案 0 :(得分:0)
尝试进行Axios之类的操作来发出实际的请求。它为您处理了很多繁重的工作:
const axios = require('axios');
function domainUpdate() {
console.log(`[SERVER] Posting to Google's Servers...`)
let username = process.env.USERNAME || ``;
let password = process.env.PASSWORD || ``;
let hostname = process.env.HOSTNAME || ``;
let url = `https://${username}:${password}@domains.google.com/nic/update?hostname=${hostname}`;
axios.get(url)
.then(res => {
console.log(`status - ${res.status}`);
console.log(`output - ${res.data}`);
})
.catch(err => {
throw err;
})
}
只要请求的格式正确,该端点看起来就返回200。链接到的Google support article列出了可能的响应,这些响应将在Axios响应对象的data
属性中。