我想使用github REST API在my github存储库中创建一个新文件。我发现以下link,但说实话,我不明白((
据我了解,我可以做POST
url:https://api.github.com/repos/MyUserName/MyRepositoryName
标题:
接受:application / vnd.github.v3 + json
身体:
{
"message": "my commit message",
"committer": {
"name": "My name",
"email": "my email"
},
"content": "base64encoded"
}
但它不起作用。你能不能写,写
1)我应该拨打哪个网址
2)此请求应包含哪些标头
3)身体应该是什么
你很接近:)让我们假设,那
1)您的登录名:YourUsername
2)您的访问令牌:123a321
3)要更新的存储库:YourRepo
4)要创建的文件:file.txt
5)包含新文件的文件夹:f1 / f2
根据这些假设,您的要求应遵循:
类型:PUT
url:https://api.github.com/repos/YourUsername/YourRepo/contents/f1/f2/file.txt
标题:
{
"Content-Type" : "application/vnd.github.v3+json",
"Authorization" : "token 123a321"
}
身体 :
{
"message": "my commit message",
"committer": {
"name": "My name",
"email": "my email"
},
"content": "base64encoded"
}