Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/396.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 Post请求向spring boot后端返回状态代码500角度请求_Java_Angular_Spring_Post_Restapi - Fatal编程技术网

Java Post请求向spring boot后端返回状态代码500角度请求

Java Post请求向spring boot后端返回状态代码500角度请求,java,angular,spring,post,restapi,Java,Angular,Spring,Post,Restapi,使用以下请求时获取500状态代码错误 createPost(postPayload: CreatePostPayload): Observable<any> { return this.http.post('http://localhost:8080/api/posts/', postPayload); } createPost(postPayload:CreatePostPayload):可观察{ 返回此.http.post('http://localhost:808

使用以下请求时获取500状态代码错误

createPost(postPayload: CreatePostPayload): Observable<any> {
    return this.http.post('http://localhost:8080/api/posts/', postPayload);
  }
createPost(postPayload:CreatePostPayload):可观察{
返回此.http.post('http://localhost:8080/api/posts/",延期付款),;
}

请求在postman上运行良好。

使用HttpClient尝试。检查post()正文和标题

createPost(postPayload:CreatePostPayload):可观察{
 createPost(postPayload: CreatePostPayload): Observable<any> {
        const headers = new HttpHeaders().set('Content-Type', 'application/json');
        return this.http.post('http://localhost:8080/api/posts', postPayload, {    
            observe: 'response',    
            headers: headers           
        });
      }
const headers=new-HttpHeaders().set('Content-Type','application/json'); 返回此.http.post('http://localhost:8080/api/posts“,后期加载,{ 观察:'回应', 标题:标题 }); }
所以我终于解决了这个问题。 事实上,身份验证令牌没有包含在post请求的头中,这就是为什么它可以在postman上正常工作的原因。多亏了穆鲁根和艾哈迈德,他们暗示要检查头球,我才得以这样解决

  createPost(postPayload: CreatePostPayload): Observable<any> {

    const headers = new HttpHeaders().set("Authorization", this.localStorage.retrieve('authenticationToken'));

    return this.http.post('http://localhost:8080/api/posts/', postPayload, {    
        observe: 'response',    
        headers: headers           
    });
  }
createPost(postPayload:CreatePostPayload):可观察{
const headers=new HttpHeaders().set(“授权”,this.localStorage.retrieve(“authenticationToken”);
返回此.http.post('http://localhost:8080/api/posts/“,后期加载,{
观察:'回应',
标题:标题
});
}

当我尝试您的代码时,错误从500切换到404。我想我在后端发现了真正的问题,但我不知道如何解决它,似乎出于某种原因,检索要分配帖子的当前用户时出错
java.base/java.lang.String不能强制转换为org.springframework.security.core.userdetails.User