ソースのダウンロード方法はこちら
kotlin の khttp の使い方 (Get)
http_post.kt
// ------------------------------------------------------------------
/*
http_post.kt
Mar/04/2018
*/
// ------------------------------------------------------------------
import khttp.post
fun main(args: Array<out String>) {
println("*** 開始 ***")
val payload = mapOf("user" to "jiro", "password" to "123456")
val url : String = "http://httpbin.org/post"
val rr = post(url,data=payload)
println(rr)
println(rr.statusCode)
println(rr.text)
println("*** 終了 ***")
}
// ------------------------------------------------------------------
Makefile
JAR=../../jar
ORG_JSON=$(JAR)/org.json.jar
http_post.jar: http_post.kt
kotlinc -cp $(ORG_JSON) http_post.kt \
khttp/KHttp.kt \
khttp/responses/Response.kt \
khttp/responses/GenericResponse.kt \
khttp/requests/Request.kt \
khttp/requests/GenericRequest.kt \
khttp/structures/cookie/Cookie.kt \
khttp/structures/cookie/CookieJar.kt \
khttp/structures/files/FileLike.kt \
khttp/structures/authorization/Authorization.kt \
khttp/structures/parameters/Parameters.kt \
khttp/structures/maps/CaseInsensitiveMap.kt \
khttp/structures/maps/CaseInsensitiveMutableMap.kt \
khttp/extensions/Extensions.kt \
-include-runtime -d http_post.jar
clean:
rm -rf http_post.jar
実行コマンド
java -jar http_post.jar