内容简介: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,妈妈再也不担心我的网络请求了
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
Head First 设计模式(中文版)
弗里曼 / O'Reilly Taiwan公司 / 中国电力出版社 / 2007-9 / 98.00元
《Head First设计模式》(中文版)共有14章,每章都介绍了几个设计模式,完整地涵盖了四人组版本全部23个设计模式。前言先介绍这本书的用法;第1章到第11章陆续介绍的设计模式为Strategy、Observer、Decorator、Abstract Factory、Factory Method、Singleton,Command、Adapter、Facade、TemplateMethod、I......一起来看看 《Head First 设计模式(中文版)》 这本书的介绍吧!