codecamp

String提交POST

所谓String提交POST,就是将一段字符串直接扔进Request请求中,字符串一般都是有格式约定的,比如是xml、json或其他等。

比如像微信开放平台(https://mp.weixin.qq.com/)的接口,所有数据提交方式就是这种。

String responseData = HttpClient
                .textBody("http://localhost:8080/okhttp-server-test/userInfo/create")
                 // 请求方式和请求url
                .json("{\"username\":\"mzlion\",\"userPwd\":\"123\"}")
                // post提交json
                //.xml("<?xml version=\"1.0\" encoding=\"utf-8\" ?>") 
                //post提交xml
                //.html("function fun(){}")
                //post提交html
                //.charset("utf-8")
                //设置编码
                .execute()
                .asString();

easy-okhttp 一个参数映射多个值
easy-okhttp 小结
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

easy-okhttp 总结

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }