【发布时间】:2017-04-25 11:10:40
【问题描述】:
我调用api支付密码:https://test-api.pin.net.au/1/cards/
我试了一下邮递员,效果很好。
当我使用 okhttp 2.7.5 申请代码 android 时
我的代码:
OkHttpClient httpClient = new OkHttpClient();
RequestBody requestBody = new FormEncodingBuilder()
.add("publishable_api_key", BuildConfig.PIN_PAYMENT_PUBLISHABLE_KEY)
.add("number", scanResult.cardNumber)
.add("expiry_month", scanResult.expiryMonth+"")
.add("expiry_year", scanResult.expiryYear+"")
.add("cvc", scanResult.cvv)
.add("address_postcode", scanResult.postalCode)
.add("name", name).build();
Request request = new Request.Builder()
.url(BuildConfig.BASE_URL_PIN_PAYMENT + Constants.API_CARD_PIN_PAYMENT)
.post(requestBody)
.build();
httpClient.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Request request, IOException e) {
view.hideLoading();
view.showError(e.getMessage());
}
@Override
public void onResponse(Response response) throws IOException {
view.hideLoading();
if (!response.isSuccessful()){
String body = "Something went wrong.Please try again later.";
try {
JSONObject object = new JSONObject(response.body().string());
body = object.getString("error_description");
} catch (JSONException e) {
e.printStackTrace();
}
view.showError(body);
}else {
view.hideLoading();
Gson gson = new Gson();
CardPinPaymentResponse paymentResponse = gson.fromJson(response.body().string() , CardPinPaymentResponse.class);
view.getTokenCardSuccess(paymentResponse);
}
}
});
但它不起作用并发出:javax.net.ssl.SSLException: Connection closed by peer
【问题讨论】: