当前位置: 首页 > 知识库问答 >
问题:

无法读取 React 从 Spring-Boot 发送的标头值

计和顺
2023-03-14

我想使用React中的超文本传输协议put方法通过标头将值发送到Spring引导。

所以我使用axios制作了一个api调用代码。

import axios from 'axios';
import {hashPwd} from '../../login/presentation/Encryptpwd'

export async function  ChangeNewPwd(newPwd) {
    alert(newPwd);
    const hash = hashPwd(sessionStorage.getItem("memberHash")+newPwd);
    alert(hash);
    let result;
    return await axios.put("/member/pwd",{
        headers: {
            Authorization:hash
        }
    })
    .then(function(res){
        result = res.data;
        return result;        
    })
    .catch(function(error){
        console.log(error);
        result = 500;
        return result;
    })
}

但是spring boot无法读取头值并发送此错误

w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingRequestHeaderException: Required request header 'Authorization' for method parameter type String is not present]

我不知道为什么我会收到此错误。我该如何解决这个问题?

下面我来展示一下我的春装开机代码。

    @PutMapping("/pwd")
    public int updatePwd(@RequestHeader("Authorization") String autho){
        logger.info("Changing pwd!!!");
        logger.info(autho);
        return 500;
    }

共有1个答案

马欣荣
2023-03-14

我认为头需要在< code>put方法的第三个参数中传递。第二个参数是要在主体中发送的数据。

await axios.put("/member/pwd", null, {
  headers: { Authorization: hash }
})
 类似资料:
  • 我正在使用nginx和Firebug+FirePHP,当我试图加载页面时,我得到了一个错误: 我们在开发环境中记录了很多东西,我想这就是使用FirePHP时出现问题的原因。在这里阅读了类似的其他问题后,似乎有以下设置之一:

  • 问题内容: 我是PHP的新手,我刚刚练习了PHP setcookie()并失败了。 http:// localhost / test / index.php http:// localhost / test / view.php 但是我无法运行index.php,像这样的IE警告。 毫无疑问,我启用了IE 6 cookie。 我上面的程序有什么问题吗?谢谢。 使用WinXP OS和XAMPP 1.

  • 如何在nodejs中发送文件,我正在创建一个页面应用程序,所以我只想abcd.html页面首次按要求交付,这是我的代码 app.js 对页面的响应 发送后,它总是给出无法设置的标题,下面是控制台输出 错误:SendStream禁止。SendStream出错(/home/pitu/CODING/NODE-PROJECTS/chichat/NODE\u modules/express/NODE\u m

  • 在尝试HTTP头时,我在服务器上设置了无法访问java脚本。下面是我的代码。好心的一些帮助我解决这个问题。 Java脚本: 谢谢,我需要在java脚本上读取头值。

  • 我有这种情况。我正在用Spring Boot开发一个REST服务,我有一个dependency jar,这是另一个Spring Boot项目,我使用以下方法将其作为一个依赖项包括在内: https://docs.spring.io/spring-boot/docs/2.1.4.release/maven-plugin/examples/repackage-classifier.html 一切都编译

  • 问题内容: 我收到这些错误: 2014/05/24 11:49:06 [error] 8376#0: *54031 upstream sent too big header while reading response header from upstream, client: 107.21.193.210, server: aamjanata.com, request: “GET /the-br