HttpPost request = new HttpPost(url);// 先封装一个 JSON 对象JSONObject param = new JSONObject();param.put("name", "rarnu");param.put("password", "123456");// 绑定到请求 EntryStringEntity se = new StringEntity(param.toString());request.setEntity(se);// 发送请求HttpResponse httpResponse = new DefaultHttpClient().execute(request);// 得到应答的字符串,这也是一个 JSON 格式保存的数据String retSrc = EntityUtils.toString(httpResponse.getEntity());// 生成 JSON 对象JSONObject result = new JSONObject( retSrc);String token = result.get("token");
1、编程语言
//----1、
HttpPost request = new HttpPost(url);
// 先封装一个 JSON 对象
JSONObject param = new JSONObject();
param.put("name", "rarnu");
param.put("password", "123456");
// 绑定到请求 Entry
StringEntity se = new StringEntity(param.toString());
request.setEntity(se);
// 发送请求
HttpResponse httpResponse = new DefaultHttpClient().execute(request);
// 得到应答的字符串,这也是一个 JSON 格式保存的数据
String retSrc = EntityUtils.toString(httpResponse.getEntity());
// 生成 JSON 对象
JSONObject result = new JSONObject( retSrc);
String token = result.get("token");
2、jQuery
$.post("getUserMessage.ashx?t=" + Math.random(), { userName: txtUserName.val(), userPassWord: txtPassWord.val() }, function (json) {
if (json) {
//返回Json数据处理
}
}, "json");
https://gist.github.com/9457c486af9644cf6b18