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 ?