Angular 如何使用API更新GIT中的文件-给出错误404错误
我试图使用API更新GIT中的文件,并得到错误代码404Angular 如何使用API更新GIT中的文件-给出错误404错误,angular,git,github,httpclient,github-api,Angular,Git,Github,Httpclient,Github Api,我试图使用API更新GIT中的文件,并得到错误代码404 updateServersonGIT(servList: string): Observable<Array<any>> { return this.http.put<Array<any>>("https://api.github.com/repos/amshreyas/servers/contents/serv.json",{"Authorization" : "token <
updateServersonGIT(servList: string): Observable<Array<any>> {
return this.http.put<Array<any>>("https://api.github.com/repos/amshreyas/servers/contents/serv.json",{"Authorization" : "token <my token>",servList}).pipe(catchError(this.handleError));
}
updateServersonGIT(servList:string):可观察{
返回此.http.put(“https://api.github.com/repos/amshreyas/servers/contents/serv.json,{“Authorization”:“token”,servList}.pipe(catchError(this.handleError));
}
我已经生成了oAuth令牌。
请告知 它可能会失败,因为您没有在文档中指定要与
PUT一起使用的必填字段:
您尤其需要确保提供以下字段:
消息
-要与更改关联的提交消息
committer
-包含提交者名称和电子邮件的JSON对象
content
新文件内容的base64编码字符串
以下是文档中的一个示例:
{
"message": "my commit message",
"committer": {
"name": "Monalisa Octocat",
"email": "octocat@github.com"
},
"content": "bXkgbmV3IGZpbGUgY29udGVudHM="
}
我不清楚是否发生了这种情况,因为该示例没有提供足够的信息在本地为其他人运行
如果您的令牌没有设置public\u repo
的话,它也可能会失败。我没有在http.put方法中正确地放置数据和HttpOptions。现在已经解决了。谢谢