我目前正在使用我的服务器上的axios通过Express向API发出GET请求。我的请求状态为200,并且能够记录所需的数据。
问题是在请求之后,我收到此错误:
TypeError:将圆形结构转换为JSON
,请求只是挂起而不是完成。
我已经看过Stackoverflow上的其他示例,但是它们都需要某种“创可贴”解决方案,这不是我想要的。如果有人能破译可能导致此问题的原因,我将不胜感激!
这是我的server.js文件中的get请求的样子
const path = require('path');
const express = require('express');
const http = require('http');
const fs = require('fs');
const socketIO = require('socket.io');
const bodyParser = require('body-parser')
import axios from 'axios';
import env from '../env.config.json';
const PORT = require('../env.config.json').SERVER.PORT;
const publicPath = path.join(__dirname, '../public');
import api from './routers/api-routing';
var app = express();
var server = http.createServer(app);
const port = PORT || 3000;
app.use(express.static(publicPath));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true}));
const io = socketIO(server);
app.get('/pingCrm', (request, response) => {
var url = 'https://OURACCOUNTNAME.nocrm.io/api/v2/ping'
var apikey = "API_KEY"
axios.get(url, {
headers: {'X-API-KEY': apikey, content_type: "json", accept: "application/json"}
}).then(function(data){
console.log(data.data);
response.send(data);
}).catch(function(error){
console.log("Error: " + error);
})
})