javascript - 向以太坊网络发出 Http 请求
问题描述
目前正在尝试通过 javascript 中的 axios post 方法将一些数据发布到以太坊网络,但我目前收到以下错误:
dispatchXhrRequest @ xhr.js:177
xhrAdapter @ xhr.js:13
dispatchRequest @ dispatchRequest.js:52
Promise.then (async)
request @ Axios.js:61
wrap @ bind.js:9
(anonymous) @ index.js:18
index.js:27 Error: Request failed with status code 400
at createError (createError.js:16)
at settle (settle.js:17)
at XMLHttpRequest.handleLoad (xhr.js:62)
至于我的代码,
const server = "http://localhost:4030";
const axios = require('axios');
console.log(document.getElementById("search"))
document.getElementById("search").addEventListener('click', () => {
//Obtain BlockID value from front end
const BlockId = document.getElementById("blockID").value;
console.log(BlockId);
//Incorporates both transaction parameters and a signature in the body request
//A request body is data sent by the client to your API
//In this case, we want to send over the BlockID
axios({
method: 'post',
url: "https://kovan.infura.io/v3/025faa826802466c8c568db0baa4aa32",
data: {
blockID: BlockId
}
}).then((response)=>{
console.log(response);
},(error) => {
console.log(error);
});
});
我相信这个问题很可能是由于我发布到网址的类型而引起的。但是,我不太确定类型提交有什么问题 - 任何建议都将受到高度赞赏!
解决方案
推荐阅读
- ruby-on-rails - Rails:如何根据表 A 中的每条记录显示表 B 中的所有关联记录
- java - 如何将两个以上的对象从 java 方法返回到 servlet
- javascript - 如何在 ng-repeat 中使字段显示为没有 HTML 代码的文本
- validation - 带有验证器问题的primefaces日历更改事件
- bash - 为什么 'eval "MYVALUE=mystring" export MYVALUE' 只适用于 bash 而不是 zsh?
- vue.js - 我应该如何在 Vue JavaScript App 的 axios 调用中使用 .then 和 .catch?
- java - 无法理解为什么此方法无法解决
- python - 如何获得numpy数组和浮点数之间的最小值?
- c - 条件运算符在算术运算中的行为
- angular - 带有业力和角度4的vscode调试器