首页 > 解决方案 > 向以太坊网络发出 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);
});

});

我相信这个问题很可能是由于我发布到网址的类型而引起的。但是,我不太确定类型提交有什么问题 - 任何建议都将受到高度赞赏!

标签: javascriptethereum

解决方案


推荐阅读