我正在尝试将Hubspot Form与nodejs连接起来,这给了我一个错误。我已经在本地服务器以及远程heroku服务器上进行了测试。这是我的代码。
app.post('/contact', (req, res) => {
//require Node modules
var https = require('https')
var querystring = require('querystring')
// global variables
const HUB_ID = "My_HUB_ID";
const FORM_GUID = "MY_FORM_ID";
var postData = querystring.stringify({
'email': "test@gmail.com",
'firstname': "Test User",
'phone': "03001234567",
'message': "Hello World!!!",
'hs_context': JSON.stringify({
"hutk": '',
"ipAddress": req.headers['x-forwarded-for'] || req.connection.remoteAddress,
"pageUrl": "/contact",
"pageName": "Contact"
})
})
var options = {
hostname: 'forms.hubspot.com',
path: '/uploads/form/v2/' + HUB_ID + '/' + FORM_GUID,
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': postData.length
}
}
var request = https.request(options, function(response){
console.log("Status: " + response.statusCode)
console.log("Headers: " + JSON.stringify(response.headers))
response.setEncoding('utf8')
response.on('data', function(chunk){
console.log('Body: ' + chunk)
});
});
request.on('error', function(e){
console.log("Problem with request " + e.message)
});
// post the data
request.end();
res.json({"message": "Welcome to Bazaristan E-Commerce Online web portal"});
});
有趣的部分在php中测试了此代码,并且工作正常。 我收到以下错误:
请求错误的问题:读取ECONNRESET