// 使用 OkHttp 进行调用
Map<String, Object> data = new HashMap<>();
data.put("appId", "AB00000004");
data.put("appKey", "3d58bcfbf47e05fc593ac2fe0508d213");
Gson gson = new Gson();
RequestBody body = RequestBody.create(gson.toJson(data), MediaType.parse("application/json; charset=utf-8"));
Request request = new Request.Builder()
.url("https://ecom-api.ottpay.com/api/v1/auth/token")
.post(body)
.build();
final OkHttpClient httpClient = new OkHttpClient();
try (Response response = httpClient.newCall(request).execute()) {
if (!response.isSuccessful()){
throw new IOException("请求失败 " + response);
}
// 得到响应结果
System.out.println(response.body().string());
} catch (IOException e) {
throw new RuntimeException(e);
}