admin管理员组文章数量:1333476
I want to store JSON data in a database using Axios in node js. This is my node js code
const axios = require('axios');
const url = 'http://api/api/master_ab_store';
axios.post(url, {
"data":[{"external_id":"-000001","code":"- ","name":"INVESTINDO","Phone":"031-5482334","Address":"Jalan Kelapa Puyuh","status_ab":"A"}]
})
.then(function(res){
console.log(res);
})
.catch(function(err){
console.log(err);
})
But i got an error like this
C:\cs_test>node index.js
Error: getaddrinfo ENOTFOUND 3128
at GetAddrInfoReqWrap.onlookup [as onplete] (dns.js:67:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '3128',
config: {
url: 'http://api/api/master_ab_store',
method: 'post',
data: '{"data":[{"external_id":"-000001","KodeAB":"- ","NamaAB":"SUMBER ARTHA INVESTINDO","Phone":"031-5482041-44","Fax":"031-5482048","Address":"Kedungdoro No. 60 Lantai 7;Jawa Timur;Surabaya;60251","status_ab":"A"}]}',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=utf-8',
'User-Agent': 'axios/0.21.1',
'Content-Length': 211,
host: 'api'
},
In postman, it's running well
How to fix this issue? help me because I'm newbie in node js
I want to store JSON data in a database using Axios in node js. This is my node js code
const axios = require('axios');
const url = 'http://api/api/master_ab_store';
axios.post(url, {
"data":[{"external_id":"-000001","code":"- ","name":"INVESTINDO","Phone":"031-5482334","Address":"Jalan Kelapa Puyuh","status_ab":"A"}]
})
.then(function(res){
console.log(res);
})
.catch(function(err){
console.log(err);
})
But i got an error like this
C:\cs_test>node index.js
Error: getaddrinfo ENOTFOUND 3128
at GetAddrInfoReqWrap.onlookup [as onplete] (dns.js:67:26) {
errno: -3008,
code: 'ENOTFOUND',
syscall: 'getaddrinfo',
hostname: '3128',
config: {
url: 'http://api/api/master_ab_store',
method: 'post',
data: '{"data":[{"external_id":"-000001","KodeAB":"- ","NamaAB":"SUMBER ARTHA INVESTINDO","Phone":"031-5482041-44","Fax":"031-5482048","Address":"Kedungdoro No. 60 Lantai 7;Jawa Timur;Surabaya;60251","status_ab":"A"}]}',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json;charset=utf-8',
'User-Agent': 'axios/0.21.1',
'Content-Length': 211,
host: 'api'
},
In postman, it's running well
How to fix this issue? help me because I'm newbie in node js
Share Improve this question edited Jun 10, 2021 at 7:56 Rahmat Effendi asked Jun 10, 2021 at 4:19 Rahmat EffendiRahmat Effendi 3433 gold badges11 silver badges30 bronze badges 10-
1
Make sure the URL
http://api/api/master_ab_store
is correct.ENOTFOUND error means the domain that you are trying to reach is unavailable or wrong
– Đăng Khoa Đinh Commented Jun 10, 2021 at 4:47 -
Are you serving the api on your local machine? If so I would expect the url to be somthing like
http://localhost:8080/api/api/master_ab_store
orhttp://127.0.0.1:5001/api...
– Mark Davich Commented Jun 10, 2021 at 4:55 - @ĐăngKhoaĐinh when I test it on the postman, It's running well – Rahmat Effendi Commented Jun 10, 2021 at 7:15
- @MarkDavich yes, the API on my local server. I make a dummy domain, I'm setting it on host file and vhost file xampp – Rahmat Effendi Commented Jun 10, 2021 at 7:17
-
@Rahmat Drrendi, Side note, what database are you using? Does your post data need to be a string in the manner that
JSON.stringify(pojo)
produces in javascript? Are you using a node backend? or something else? Did you try putting a forward slash at the end of your url in the node frontend? likeurl = ...master_ab_store/
– Mark Davich Commented Jun 10, 2021 at 7:31
2 Answers
Reset to default 3I solved my issue. This is because the server has a proxy. So when I remove it, it's running. Thanks to @Mark Davich and @ĐăngKhoaĐinh for helping me
Make sure your url (baseURL) is correct. I use the free version of postman to check my api calls. Is your data object supposed to be an array? If not your endpoint my not know what to do with it
I don't use Axios or promises the way you do, so here is an alternative version of what you are trying to do. Maybe you it will help. The async/await
replace the .then/.catch
import Axios from "axios";
axios = Axios.create({
baseURL: 'http://api/api/master_ab_store',
timeout: 10000,
withCredentials: true
});
let data = {
external_id: "-000001",
code : "- ",
name: "INVESTINDO",
Phone: "031-5482334",
Address: "Jalan Kelapa Puyuh",
status_ab: "A"
}
async getData(data) {
try {
const res = await axios.post(url, data);
console.log(res.data); // .then
} catch (error) {
console.log(err); // .catch
}
}
本文标签: javascriptError getaddrinfo ENOTFOUND 3128 when post data using Axios in node jsStack Overflow
版权声明:本文标题:javascript - Error: getaddrinfo ENOTFOUND 3128 when post data using Axios in node js - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742351561a2458596.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论