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 ...


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

查看所有标签

猜你喜欢:

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

Web Standards Creativity

Web Standards Creativity

Andy Budd、Dan Rubin、Jeff Croft、Cameron Adams、Ethan Marcotte、Andy Clarke、Ian Lloyd、Mark Boulton、Rob Weychert、Simon Collison、Derek Featherstone / friends of ED / March 19, 2007 / $49.99

Book Description * Be inspired by 10 web design lessons from 10 of the world's best web designers * Get creative with cutting-edge XHTML, CSS, and DOM scripting techniques * Learn breathtakin......一起来看看 《Web Standards Creativity》 这本书的介绍吧!

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

在线压缩/解压 CSS 代码

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具