java实现post发送json,实现登录并接受登录信息

java实现post发送json,实现登录并接受登录信息

  void test()
    {
        //网络等阻塞需要线程操作
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {

                    Map<String, Object> headers = new HashMap<>();

                   //需要传递的数据json headers.put("content-type", "application/json");
                    headers.put("User-Agent", "Dalvik/2.1.0");

                    HashMap<String,String> hm = new HashMap<String,String>();
                    hm.put("Password", "17ffe5be28a1db29b33375354794978d" );
                    hm.put("Phone", "18196646056^android_1.52");
                    hm.put("Signature", "771c74c48b57d57888a37189b52ff42a");

                    Charset cs = Charset.forName("utf-8");
                    String result = Requests.post("http://account.seasidecity.cn/api/Member/Login")
                        //    .headers(headers )
                            .requestCharset(cs)//请求编码
                            .body(hm)//发送的参数
                            .send()
                            .withCharset(cs)//接收编码
                            .readToText();
                    Log.i("回传数据","result-->" + result);

                }catch (Exception e)
                {
                    Log.i("test","ERROR2");
                    PostGetUtil.sendData();
                }
            }
        }).start();
    }

猜你喜欢

转载自blog.csdn.net/m0_37909265/article/details/82117489