1

I try to use okhppt library post json to web api , so this is my json value :

"apiName":"getUserInfo",

"accountNo":"cb2c2041d9763d84d7d655e81178f444",

"stationNo":"NURS4",

"bedNo":"329-1"

and my url is : http://xxx.xxx.xxx:8090/api/getUserInfo

      new Thread() {
                @Override
                public void run() {
                    postJson();
                }
            }.start();

         private void postJson() {
            MediaType JSON = MediaType.parse("application/json; charset=utf-8");
            JSONObject jsonObject = new JSONObject();
            try{
                  jsonObject.put("apiName", "getUserInfo");
                  jsonObject.put("accountNo", "cb2c2041d9763d84d7d655e81178f444");
                  jsonObject.put("stationNo", "NURS4");
                  jsonObject.put("bedNo", "329-1");

              }catch (JSONException e){
                 e.printStackTrace();
              }

            OkHttpClient okHttpClient = new OkHttpClient();
            RequestBody requestBody = RequestBody.create(JSON, jsonObject.toString());
            Request request = new Request.Builder()
                            .url("http://xxx.xxx.xxx:8090/api/getUserInfo")
                            .header("Authorization", default_token)
                            .post(requestBody)
                            .build();

              Response response = null;
              try {
                     response = okHttpClient.newCall(request).execute();
                     String resStr = response.body().string();
                     Log.d(TAG, "postJson: " + resStr);
                } catch (IOException e) {
                  e.printStackTrace();
                }

[Edit]

I get postJson return is cEkR8bsOXn6HiS3wnTIcBzVhcmugbay/phdNPYUSyDa1vYVZWpq+Ks4Q1eCBrP0L

  public static String decrypt(byte[] cryptograph){
   try {
        Cipher cipher = Cipher.getInstance("AES/ECB/PKCS7Padding");
        SecretKeySpec mSecretKeySpec = new SecretKeySpec(AES_KEY.getBytes(), "AES");
        cipher.init(Cipher.DECRYPT_MODE, mSecretKeySpec);
        byte[] content = cipher.doFinal(org.bouncycastle.util.encoders.Base64.decode(cryptograph));
        return new String(content);
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
  }

org.bouncycastle.util.encoders.Base64.decode is error , how to fix it ?

Edric
  • 24,639
  • 13
  • 81
  • 91
leona lin
  • 25
  • 5
  • 2
    This may help you [https://stackoverflow.com/questions/34179922/okhttp-post-body-as-json][1] –  Jan 18 '20 at 04:07
  • @javierdromero : token ?? – leona lin Jan 18 '20 at 04:16
  • Use asynctask to make the network request. – Masoom Badi Jan 18 '20 at 04:30
  • what does this response mean `cEkR8bsOXn6HiS3wnTIcBzVhcmugbay/phdNPYUSyDa1vYVZWpq+Ks4Q1eCBrP0L` ? and what exactly you need to do now – Masoom Badi Jan 18 '20 at 04:33
  • @Sam: I think it need to decrypt resStr(String) – leona lin Jan 18 '20 at 06:03
  • What is the server supposed to return for this request? – Henry Jan 18 '20 at 09:24
  • @Henry xwuORy5x0StoGzCiVvVy9jCWqHV8dVmQn3h4JWmaFzWoVbGFolOfalSfXKerwLADrSDVcjW0/KUXvh4T+wm5kA2Nnhu8B+95hrblOVyCsZ0PeotVNj/Yzfy29eT36xHQMHrWdyhDoab0JyelcJ3U2PkPk+s36XgnF7BKs0DoYxRsH3xUf1rNetPRaiOiJymFP0XYVDw8F6GMhoLkZ0s8NwtP+fODaTIDPmbp18/OcBn/0G6UU63+Nmej3vp3Upg8gPtjwnSlFRlb5lBTS72lPU6ya1SQPt6R8IwRjjGLNr6Bw3NvN3TQrBK1P5Snt+dsyCfRjip1wRDDEsFz4dWcaqM6Hj6SvLcgNMeo73peThS3Hl24CUSQPycJuH9uKdYr6YPM+449A6yCu1uzy3ItwiZOdRyMKdpjRI4iwG3Hce72j7CEOeu4aSNQh+ – leona lin Jan 18 '20 at 10:32

0 Answers0