所以基本上我试图向 API 发出大量(大约 25,000 个)GET 请求。我使用 axios 作为我的库来进行 HTTP 调用。
所以我有:
dsHistPromises.push(axios.get(url))
Run Code Online (Sandbox Code Playgroud)
然后我正在使用:
axios.all(dsHistPromises)
.then(function(results) {
results.forEach(function(response){
if (format === lists.formats.highlow) {
storage.darkskyHistoryHighLow.push(requests.parseDarkskyHighLow(response, city))
}
// parse data here and print it to files...
})
}).catch(err => {
throw err
})
Run Code Online (Sandbox Code Playgroud)
履行我所有的承诺。
当我尝试运行我的代码时,我收到如下错误
(node:10400) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): Error: read ECONNRESET
Run Code Online (Sandbox Code Playgroud)
我必须想象这是我正在连接的 API 的问题。服务器可能很难管理我的请求,对吗?
有什么技巧可以解决这个问题吗?
我有一个 Jasmine 测试,其中包含一些 HTTP 请求。我正在使用 Axios 进行基于承诺的 HTTP 访问,但由于某种原因我得到了axios is not defined. 我已经跑了npm install axios --save
var request = require('axios');
var constants = require('../../lib/constants.js');
describe('Signing into the application', function () {
it('returns 200 OK', function () {
axios.get(constants.Endpoint)
.then(function (response) {
console.log(JSON.stringify(response));
})
.catch(function (error) {
console.log(JSON.stringify(error));
});
});
});
Run Code Online (Sandbox Code Playgroud)
这是输出:
Failures:
1) Signing into the application returns 200 OK
Message:
ReferenceError: axios is not defined
Stacktrace:
ReferenceError: axios is not defined
at jasmine.Spec.<anonymous> (C:\Users\la\Documents\tests\spec\integration\sign-in\sign-in-spec.js:6:9)
Run Code Online (Sandbox Code Playgroud)
这里是package.json …
axios 获取请求后,Vue.js 中的 HTML 未更新。HTML是:
<span @click="tryResponse">
Data_object: {{ data_object }} <br>
Data_object.serial: {{ data_object.serial }} <br>
</span>
Run Code Online (Sandbox Code Playgroud)
数据:
data(){
return{
data_object: {},
}
},
Run Code Online (Sandbox Code Playgroud)
方法:
methods: {
tryResponse() {
axios.get('http://127.0.0.1:8000/source/groups/15').then((response) => {
this.data_object.serial = response.data});
}
Run Code Online (Sandbox Code Playgroud)
这一切都发生在一个名为 App.vue 的文件中(如果这很重要)。
如果我查看 chrome 开发工具 Vue,我可以看到数据对象确实更新并填充了正确的信息。但它不会在页面上的 html 中更新。
编辑:如果我这样做,一切正常:
this.data_object = response.data
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时问题就来了:
this.data_object.serial = response.data
Run Code Online (Sandbox Code Playgroud) 我已经像这样设置了我的 axios:
const agent = new https.Agent({
rejectUnauthorized: false
});
Run Code Online (Sandbox Code Playgroud)
并发送这样的 get 调用:
let data = await axios.get('https://www.skechers.com/en-us/', {
httpsAgent: agent
});
Run Code Online (Sandbox Code Playgroud)
但是对于一些网址,我的请求失败并出现此错误:
请求失败,状态码为 403
导致此错误的可能原因是什么。我试过如下设置标题,但仍然收到错误
let data = await axios.get('https://www.skechers.com/en-us/', {
httpsAgent: agent
});
Run Code Online (Sandbox Code Playgroud) 我有一个文件调用 find.js,我使用节点 find.js 运行,我的节点是版本 10 我不知道为什么我无法使用 async await。
const axios = require("axios");
const execute = async () => {
let searchResult;
try {
searchResult = await axios.post(
"https://example.io/car",
{
ids: [12,31],
},
{
headers: {
"Accept-Language": "en-US",
},
}
);
} catch (error) {
console.log("error", error);
}
return searchResult;
};
console.log(await execute()); // error on this line
Run Code Online (Sandbox Code Playgroud) 您好,我是 nodejs 的新手,当我运行我的应用程序时出现此错误“错误:连接 ECONNREFUSED 127.0.0.1:80”这是我的代码
const axios = require('axios')
const url = 'api.openweathermap.org/data/2.5/weather?q=London,uk&appid=4dd23b28fb57078c0d5ec9c653e203b2'
axios.get(url)
.then((response) =>{
console.log(response)
})
.catch(function (error) {
console.log(error);
})
Run Code Online (Sandbox Code Playgroud)
先感谢您
目前我有一个 axios post 请求,可以很好地将数据发送到 Spring Boot 后端。但它只是将单个数据列表包装到 json 并将其作为请求的正文发送:
例子:
sendAllData(data) {
return axios.post(API_URL + "receiveData", JSON.stringify(data),
{ headers: { "Content-Type": "application/json; charset=UTF-8" },
}).then(response=> console.log("repsonse", response.status)) // is 201
Run Code Online (Sandbox Code Playgroud)
}
它在后端接收它:
@RequestMapping(path = "/receiveData", method = RequestMethod.POST)
public ResponseEntity<Void> receiveData(@RequestBody Collection<ActivePOJO> activitePOJOS) {
//DO WORK WITH activePOJOS DATA
return new ResponseEntity<>(HttpStatus.CREATED);
}
Run Code Online (Sandbox Code Playgroud)
但是,除了这些信息,我还需要发送一些其他信息,如 user.id(例如),所以我需要我的后端接收这样的信息:
public ResponseEntity<Void> receiveData(@RequestBody Collection<ActivitePOJO> activePOJOS, Long userID)
Run Code Online (Sandbox Code Playgroud)
但我不知道我应该用哪种方式准备 axios 帖子。我应该使用 params 而不是 body 吗?
我有一个管理区域和一个供普通用户使用。现在,当我的会话到期时,我会从管理区域重定向到主页,我必须刷新页面才能将我重定向到/login. 附注。我使用 Vue.js 作为前端。
我想在会话过期时重定向到我的 /login 页面,而不是主页,那时主页应该是不可见的。
网页.php
// Admin routes
Route::middleware(['can:admin'])->group(function () {
// all routes for admin, and when my session expire I get redirected from here
}
Route::middleware('guest')->get('/', function () {
return redirect('/login');
});
// Normal user routes
Route::middleware('auth')->get('/', function () {
return view('layouts.app');
});
Route::middleware('auth')->get('/{any}', function () {
return view('layouts.app');
})->where('any', '.*');
Run Code Online (Sandbox Code Playgroud)
身份验证服务提供者
public function boot()
{
$this->registerPolicies();
Gate::define('admin', function ($user) {
return !empty($user->roles()->where('admin_area', true)->first());
});
Gate::define('normal', function ($user) {
return !empty($user);
});
} …Run Code Online (Sandbox Code Playgroud) CORS当我尝试通过 Web 应用程序将数据发布到我的 Google 电子表格时收到错误响应。这是我得到的错误:
从源“http://localhost:3000”访问“myGoogleSpreadSheetApiURL”处的 XMLHttpRequest 已被 CORS 策略阻止:对预检请求的响应未通过访问控制检查:不存在“Access-Control-Allow-Origin”标头在请求的资源上。
我做了一些解决方案,我在互联网上搜索,但我无法解决问题......我已经可以从 Google 电子表格中获取我的 JSON 数据。
当我推送我的 时createButton,我可以在我的 Google 电子表格上发布和写入我的数据。
我应该如何修复我的代码?你有什么主意吗 ?
这是我的 react.js 代码:
import React,{ Component } from 'react';
import Paper from '@material-ui/core/Paper';
import axios from 'axios';
axios.defaults.baseURL = 'http://localhost:3000';
axios.defaults.headers.post['Content-Type'] = 'application/json;charset=utf-8';
axios.defaults.headers.post['Access-Control-Allow-Origin'] = '*';
const api = 'https://myGoogleSpreadSheetApiUrl';
class Price extends Component {
state = {
info: []
};
constructor(){
super()
axios.get(api)
.then((res) =>{
console.log(res.data)
this.setState({
info: res.data
})
})
};
createInfo = () …Run Code Online (Sandbox Code Playgroud) 下面提交的代码是 axios。哪个工作正常。但是 javascript 提取不起作用。让我知道代码中有什么问题。如何修复它。请用简单的方式解释一下。谢谢!
import React, {useEffect, useState} from 'react'
import axios from 'axios'
function Datafetching() {
const [posts, setposts] = useState([])
const getMovieRequest = async () => {
const url = `http://jsonplaceholder.typicode.com/posts`;
const response = await fetch(url);
const responseJson = await response.json()
if (responseJson.data){
setposts(responseJson.data)
console.log(responseJson.data)
}
}
useEffect(() => {
// axios.get('http://jsonplaceholder.typicode.com/posts')
// .then(res => {
// console.log(res)
// setposts(res.data)
// })
// .catch(err => {
// console.log(err)
// })
getMovieRequest()
})
return (
<div>
<ul>{
posts.map(post => …Run Code Online (Sandbox Code Playgroud) axios ×10
javascript ×7
node.js ×4
reactjs ×2
vue.js ×2
api ×1
cors ×1
ecmascript-6 ×1
fetch ×1
get ×1
http ×1
jasmine ×1
laravel ×1
laravel-7 ×1
react-native ×1
spring ×1
web-scraping ×1