Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java axios.delete()出现403错误。。。然而,这在POSTMAN中有效,并且axios.post方法工作正常_Java_Reactjs_Axios - Fatal编程技术网

Java axios.delete()出现403错误。。。然而,这在POSTMAN中有效,并且axios.post方法工作正常

Java axios.delete()出现403错误。。。然而,这在POSTMAN中有效,并且axios.post方法工作正常,java,reactjs,axios,Java,Reactjs,Axios,我有一个与STS(java)后端交互的REACT前端 删除功能: deleteCustomer = (someone) => { // eslint-disable-next-line let url = "http://localhost:8080/customer/" + `${someone}` axios.delete(url) .catch(function (error) { console.log("Deletion failed

我有一个与STS(java)后端交互的REACT前端

删除功能:

deleteCustomer = (someone) => {
    // eslint-disable-next-line
    let url = "http://localhost:8080/customer/" + `${someone}`
    axios.delete(url)

    .catch(function (error) {
      console.log("Deletion failed with error: " + error);
    });
  }
触发它的HTML:

      {this.state.customers.map(p => (

        <span onClick={() => this.deleteCustomer(p.customerid)} title="Delete Customer"><img alt="delete" className="hiddenIcon actionDelete" src={deleteHover} /></span>

        ))}
因此,当我在POSTMAN应用程序中运行DELETE-type请求时,记录将被删除,不会出现任何问题。但是,尝试从React前端运行该函数时会出现错误403(网络错误)

我假设缺少某个标题或参数?如果需要授权,如何查找授权密钥

我试着跟着这个:

但没有得到任何决议


非常感谢您的帮助-谢谢。

这可能与CORS有关,请尝试向端点添加
@CrossOrigin
注释,如下所示:

@DeleteMapping("/{customerid}")
  public void deleteCustomer(@PathVariable Long customerid) {
    customerRepository.deleteById(customerid);
  }
@CrossOrigin
@DeleteMapping("/{customerid}")
public void deleteCustomer(@PathVariable Long customerid) {
    customerRepository.deleteById(customerid);
}

这似乎可以做到!你让我一整天都很开心。非常感谢你!您是否尝试了从浏览器到资源的get请求?如果是Cors的问题,你会知道的。除此之外,403表示服务器拒绝。确保传递所需的标题?这些信息是不够的,因为我们不知道服务器拒绝的依据是什么。