首页 > 解决方案 > Gitlab API更新存储库中的现有文件,在rest模板中给出400错误

问题描述

我正在尝试使用 gitlab v4 api 在 repo 中编辑现有文件,当我尝试使用 postman rest 客户端编辑文件时,它执行时没有任何问题,返回 200 状态。当我对 SpringBoot RestTemplate 进行相同尝试时,我总是以 400 bad request 错误告终。我完全不知道实际发生了什么。休息网址:https://domainname/api/v4/projects/51/repository/files/src%2Fmain%2Fresources%2Fapplication.yml

使用 LOG 打印的请求对象是:

[branch=master, content=server:port: value, commit_message=port number updated, file_path=src%2Fmain%2Fresources%2Fapplication.yml]

resttemplate API 调用,

HttpEntity<?> entity = new HttpEntity<Object>(request, header);
    restTemplate.exchange(gitlabApiUrl, HttpMethod.PUT, entity, Object.class);

当我与邮递员尝试相同的请求正文时,我获得了 200 次成功

这是其余的端点,https://domainname/api/v4/projects/:projectId/repository/files/:file_path

有谁知道发生了什么。

参考文档:https ://docs.gitlab.com/ee/api/repository_files.html#update-existing-file-in-repository

标签: spring-bootresttemplategitlab-api

解决方案



推荐阅读