1.先申請一個token 在github中Setting/Developer settings 中 這個token 出現一次,最好保存下
2.上傳文件到項目中(如果沒有,自己在github中創建一個項目)
1.使用PUT請求方式 網址爲 https://api.github.com/repos/(github用戶名)/upload/contents/(文件名:可以帶目錄)?access_token=(你申請的token)
例如:https://api.github.com/repos/JGWCoding/upload/contents/Site_Report/123.txt?access_token=xxxxx (文件可以是txt,也可以是圖片)
2.添加請求頭文件 (Content-Type: application/json)
3.添加請求內容 {"message":"commit1","content":"bXkgbmV3IGZpbGUgY29udGVudHM="}
這個content裏面的內容必須是經過Base64加密的 不然會有問題
可以使用 https://getman.cn 測試下 Content-Type 要設置爲Content-Type: application/json
官網地址:
https://developer.github.com/v3/repos/contents/#create-or-update-a-file