示例#1
0
 // put请求,以json形式封装请求参数放在请求体中。响应是json,以指定类的实例对象返回请求结果
 private void putJsonBody() {
   LoginAccount la = new LoginAccount("zhangsa", "123456");
   String url = "http://192.168.1.102:8080/Test/HelloServlet";
   RequestInfo requestInfo = new RequestInfo();
   requestInfo.url = url;
   requestInfo.contentType = RequestInfo.ContentType.CT_JSON;
   requestInfo.bodyContent = JSON.toJSONString(la); // 将LoginAccount实例属性,转成json字符串
   afeitaNet.putJson(
       requestInfo,
       new NetCallback<UserInfo>() {
         @Override
         public void onResult(UserInfo response) {
           Toast.makeText(
                   NetSampleActivity.this,
                   "get HelloServlet post 调用成功:" + response,
                   Toast.LENGTH_LONG)
               .show();
         }
       },
       UserInfo.class);
 }