kttp:用 Kotlin 做 HTTP 请求

栏目: 后端 · 前端 · 发布时间: 8年前

内容简介: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 ...


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

JavaScript & jQuery

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》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换