kttp:用 Kotlin 做 HTTP 请求

## Kttp a http tool for Kotlin and Java

0. download

download kttp.jar file and add to our project

1. usage in Kotlin

var kttp: Kttp = Kttp()
kttp.zero_setUrlAddress("http://chatbot.kompasim.cn/api.php")
kttp.one_addUrlPrams("requestType=talk&userInput=hello")
kttp.two_openConnection()
kttp.three_addHeader("name1", "value1")
kttp.three_addHeaders(mapOf(Pair("name2", "value2"), Pair("name3", "value3")))
kttp.four_doPost("c=cc&d=dd")
//  kttp.four_doGet()
var result: String = kttp.five_readReasult()

2. usage in Java

Kttp kttp = new Kttp();
kttp.zero_setUrlAddress("http://chatbot.kompasim.cn/api.php");
kttp.one_addUrlPrams("requestType=talk&userInput=hello");
kttp.two_openConnection();
kttp.three_addHeader("name1", "value1");
HashMap<String, String> headers = new HashMap<>();
headers.put("name2", "value2");
headers.put("name3", "value3");
kttp.three_addHeaders(headers);
kttp.four_doPost("c=cc&d=dd");
//  kttp.four_doGet();
String result = kttp.five_readReasult();
System.out.println(result);

3. GET and POST

we have four_doPost and four_doGe to select request method . in every request , you can only call one of them.

4. more

easy steps for http and this is only for fun ...

我来评几句
登录后评论

已发表评论数()

相关站点

+订阅
热门文章