内容简介: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 ...
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网
猜你喜欢:- 详解nginx的请求限制(连接限制和请求限制)
- angular请求防抖,以及处理第一次请求失效
- RxHttp 一条链发送请求,新一代Http请求神器(一)
- RxHttp 一条链发送请求,新一代Http请求神器(一)
- 利用Jsonp跨域请求数据(原生和Jquery的ajax请求),简单易懂!
- Python网络请求库Requests,妈妈再也不担心我的网络请求了
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
JavaScript & jQuery
David Sawyer McFarland / O Reilly / 2011-10-28 / USD 39.99
You don't need programming experience to add interactive and visual effects to your web pages with JavaScript. This Missing Manual shows you how the jQuery library makes JavaScript programming fun, ea......一起来看看 《JavaScript & jQuery》 这本书的介绍吧!