我有一个原始比特币交易,我想用 Blockcypher API 广播,我使用 axios 发送 POST 请求:
var axios = require('axios')
axios.post('https://api.blockcypher.com/v1/bcy/test/txs/send', {
"tx": "010000000174770a05466c28df24425ac50dba86ead47af31778f01fa1069bf01816810a2b010000008b48304502210090c86f59c8df34979ccb485c524803e9ba1290cc4448cdbfdcc8f3cf3337102302202357e77439354acf7b178392720f433cfeac952d34098addb2eea7edcf7884c20141048520397beff2fe111c7af8aa42c99b317453b1595ec5c3b3cf9eb2059dd06b9b956165419d51a48d885aacb4df1004d7c93b30e2e53c6d4f64f9668c9fd7e92fffffffff02cd0d0000000000001976a914243170728a9278ed24b4ac7ba9df33bdadf7afd488ac00000000000000004d6a4b77723335322d33316472342d4e42412d33323132322d333435352d363933352d323334392d323334302d31323333322d39392d30322d31362d323031352d32336f6c2d313030303030303000000000"
})
.then(function (response) {
console.log(response);
})
.catch(function (response) {
console.log(response);
});
Run Code Online (Sandbox Code Playgroud)
在终端中运行时出现错误:
{ data: { error: 'Couldn\'t deserialize request: json: cannot unmarshal string into Go value of type pooch.JSONTx' }
Run Code Online (Sandbox Code Playgroud)
知道我的 POST 有什么问题吗?我试图用 tx 而不是“tx”发布,但它仍然不起作用。在文档上,他们建议这样做:
var pushtx = {
tx: "01000000011935b41d12936df99d322ac8972b74ecff7b79408bbccaf1b2eb8015228beac8000000006b483045022100921fc36b911094280f07d8504a80fbab9b823a25f102e2bc69b14bcd369dfc7902200d07067d47f040e724b556e5bc3061af132d5a47bd96e901429d53c41e0f8cca012102152e2bb5b273561ece7bbe8b1df51a4c44f5ab0bc940c105045e2cc77e618044ffffffff0240420f00000000001976a9145fb1af31edd2aa5a2bbaa24f6043d6ec31f7e63288ac20da3c00000000001976a914efec6de6c253e657a9d5506a78ee48d89762fb3188ac00000000"
};
$.post('https://api.blockcypher.com/v1/bcy/test/txs/push', JSON.stringify(pushtx))
.then(function(d) {console.log(d)});
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时,我收到错误:
TypeError: undefined is not a function
Run Code Online (Sandbox Code Playgroud)
所以我认为使用 axios 更容易,因为我至少得到了 Blockcypher 的回复。任何帮助将非常感激!
我试图在 React 项目中向这个https://www.themoviedb.org/documentation/api API发出请求,然后在我的网站上显示 JSON 数据。
我正在使用 Axios 发出请求,并且我已经能够发出请求并获取适当的 JSON 数据和 console.log 或在 Firefox 的 React 工具中查看它。但是,我很难在 ul 中显示数据。最初我有一个错误,与每个列表项都有一个唯一的键有关,我已经解决了这个问题(或者我相信)。
这是我的请求以及我如何尝试呈现数据:
import React, { Component } from 'react';
import ReactDOM from 'react-dom';
import axios from "axios";
export default class App extends Component {
constructor(props) {
super(props);
this.state = {
posts: []
}
}
componentDidMount() {
axios.get(`https://api.themoviedb.org/3/movie/now_playing?api_key=*apikeyhere*&language=en-US&page=1`)
.then(res => {
const posts = res.data.results.map(obj => [obj.title, obj.overview]);
this.setState({ posts });
});
}
/* render() {
return (
<div>
<h1>Movie API data</h1> …Run Code Online (Sandbox Code Playgroud) const config = {
headers: { "Content-Type": "application/octet-stream" }
}
let files = this.state.files
let promises = []
files.map((item ,index) => {
promises.push(axios.put(this.props.deal.authURL[index], item, config))
})
Run Code Online (Sandbox Code Playgroud)
我收到此错误:
未捕获(承诺)类型错误:无法读取未定义的属性“协议”
我的目标是将 Axios 调用的所有结果存储在 promises 数组中。然后使用Promise.all()函数一次性解决所有问题。无法弄清楚为什么会出现错误。
任何形式的帮助表示赞赏。谢谢
如何axios.get与params和config一起使用?我的代码不起作用.请帮帮我这个基本问题!
let config = {
'headers': {'Authorization': 'JWT ' + this.$store.state.token}
}
let f = 0
axios.get('http://localhost:8000/api/v1/f/', {
params: {
page: f + 1
},
config: this.config
})
Run Code Online (Sandbox Code Playgroud) 我正在使用 Nuxtjs 和内置的 Vuex 模块以及 Nuxtjs 的官方 axios。我试图从我的本地服务器获取,但它总是抛出 CORS 错误。
因此,我对 Github 的公共端点进行了 API 调用,但没有成功,仅在我的控制台中收到 CORS 错误。
我正在使用 Store 操作在组件创建生命周期中启动对服务器的 AJAX 调用。这是我的代码。
// component.vue
created () {
this.$store.dispatch('getGithubAPI')
}
// store action
async getGithubAPI ({ commit, state }) {
await this.$axios.$get('https://api.github.com/users/kaungmyatlwin', { headers: { 'Access-Control-Allow-Origin': '*' } })
.then(resp => {
console.log(resp.data)
})
}
Run Code Online (Sandbox Code Playgroud)
仍然没有运气得到它。这是被抛出到控制台的错误消息。
Failed to load https://api.github.com/users/kaungmyatlwin: Response to preflight request doesn't pass access control check: The value of the 'Access-Control-Allow-Origin' header in the response must not be …
我正在使用一个 API,该 API 显示名为 CryptoCompare 的加密货币数据。我是一个 React 菜鸟,但我已经设法使用 Axios 来执行 AJAX 请求。但是,我无法访问我想要的 JSON 元素。
这是 JSON 的样子:https : //min-api.cryptocompare.com/data/all/coinlist
这是我的要求:
import React, { Component } from 'react';
import './App.css';
import axios from "axios";
var NumberFormat = require('react-number-format');
class App extends Component {
constructor(props) {
super(props);
this.state = {
coinList: []
};
}
componentDidMount() {
axios.get(`https://min-api.cryptocompare.com/data/all/coinlist`)
.then(res => {
const coins = res.data;
//console.log(coins);
this.setState({ coinList: coins});
});
}
// Object.keys is used to map through the data. Can't map …Run Code Online (Sandbox Code Playgroud) 嗨,我建立了Udemy API,该API使用React和axios获取课程。如果chrome启用了CORS扩展名,则可以正常工作,但否则不会获取数据。
我已经问过有关此问题的问题,请花点时间阅读。我已经尝试了在线提供的所有解决方案。
我的 ajax axios 是这样的:
let formData = new FormData()
formData.append('file', user.avatar)
formData.append('selected_data', JSON.stringify(user))
axios.post('/member/profile/update',
formData, {
headers: {
'Content-Type': 'multipart/form-data'
}
}
)
.then(response => cb(response))
.catch(error => ecb(error))
Run Code Online (Sandbox Code Playgroud)
我的路线是这样的:
Route::post('update', 'member\UserController@update')->name('member.profile.update');
Run Code Online (Sandbox Code Playgroud)
如果脚本执行,它工作。我成功发送了数据
但是在这里,我想将 post 方法更改为 put 方法。因为这用于更新配置文件
我这样改变:
axios.put(...
Run Code Online (Sandbox Code Playgroud)
和路线:
Route::put('update', ...
Run Code Online (Sandbox Code Playgroud)
我没有成功发送数据。发送的数据为空
我怎么解决这个问题?
更新:
如果我console.log(user),结果是这样的:
在问这个之前,我确实看过其他类似的问题,但到目前为止,它们都没有帮助。
我有一个使用 axios 的 React 前端,可以使用 express 和 express 会话对节点后端进行 api 调用。在我的前端输入登录信息后,我将它发送到我的后端,在那里我设置一个会话并将响应返回给我在 localStorage 中设置的前端以用于客户端验证。
当我尝试从前端访问受保护的 api 端点时 - 登录后,会话没有我在其中设置的任何信息,因此,给我一个错误。但是,如果我尝试从邮递员登录并访问受保护的端点,它就可以正常工作。
这是我的快速会话配置:
router.use(session({
secret: 'notGoingToWork',
resave: false,
saveUninitialized: true
}))
Run Code Online (Sandbox Code Playgroud)
这是我通过 axios 进行的 api 调用(登录后):
axios.get(`http://localhost:5000/users/personNotes/${JSON.parse(userData).email}`)
.then(response => console.log(response);
Run Code Online (Sandbox Code Playgroud)
我不知道是什么问题,希望得到任何帮助。先感谢您!
我正在使用OpenWeatherMap API在React中创建一个天气应用程序。有输入表单和一个按钮,当我单击该按钮时,我希望看到城市名称。我这样做是从API接收数据的,但是我可以在控制台中登录时却无法在屏幕上呈现数据。
为此,我使用了三个分开的文件。App.js,Form.js(用于提交条款)和weather.js(用于API配置)。
我猜测我需要映射接收到的数据,但尚未成功。
class App extends React.Component {
state = {
city: null,
}
getWeather = async city => {
const response = await weather.get('/forecast', {
params: {
q: city
}
});
this.setState({
city: response.name,
})
console.log(city); <--- This works
}
render() {
return (
<div>
<Form loadWeather={this.getWeather} />
<p>{this.state.city}</p> <--- This doesn't work
</div>
);
}
}
Run Code Online (Sandbox Code Playgroud)
class Form extends React.Component {
state = { term: '' };
onFormSubmit = (event) => {
event.preventDefault();
this.props.loadWeather(this.state.term);
this.refs.textInput.value = ''; …Run Code Online (Sandbox Code Playgroud)