用 Postman 測試無誤後,就要用程式來 Post 啦
implementation "com.squareup.okhttp3:okhttp:4.9.3"
val okHttpClient = OkHttpClient()
val request = Request.Builder()
.addHeader(BaseConstants.AUTHORIZATION, HackMd的Token)
.url("https://api.hackmd.io/v1")
.post(要Post出去的內容)
.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
//請求失敗
}
override fun onResponse(call: Call, response: Response) {
//請求成功
}
})
val okHttpClient = OkHttpClient()
val request = Request.Builder()
.addHeader(BaseConstants.AUTHORIZATION, HackMd的Token)
.url("https://api.hackmd.io/v1")
.get()
.build()
okHttpClient.newCall(request).enqueue(object : Callback {
override fun onFailure(call: Call, e: IOException) {
//請求失敗
}
override fun onResponse(call: Call, response: Response) {
//請求成功
}
})