我在这里遇到问题,我正在使用okhttp 3
将一些参数传递给我的php
脚本。它在我使用http://
时起作用,但当我更改为https://
时,它总是说错误。
这是我的日志:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
这是我的代码的一部分:
OkHttpClient client = new OkHttpClient();
RequestBody requestBody = new MultipartBody.Builder()
.setType(MultipartBody.FORM)
.addFormDataPart("username", txtUsername.getText().toString())
.addFormDataPart("password", txtPassword.getText().toString())
.build();
Request request = new Request.Builder()
.url(my_https_url)
.post(requestBody)
.build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
Log.e("Error", e.toString());
backgroundThreadShortToast(getApplication(), "Something Happened");
}
@Override
public void onResponse(Call call, final Response response) throws IOException {
final String responseData = response.body().string();
//backgroundThreadShortToast(getApplication(), responseData);
LoginActivity.this.runOnUiThread(new Runnable() {
@Override
public void run() {
if(responseData.equals("Login Failed")){
Toast.makeText(LoginActivity.this, "Username atau password salah", Toast.LENGTH_SHORT).show();
clickcount=clickcount+1;
if(clickcount==5)
{
btnLogin.setEnabled(false);
new Handler().postDelayed(new Runnable()
{
public void run()
{
btnLogin.setClickable(true);
clickcount = 0;
}
}, 5000);
}
}else{
id_user = responseData;
checkVer();
}
}
});
}
});
当我运行我的代码时,它总是转到onFailure
。我在另一篇文章中搜索了一些信息,但我没有得到答案。有人能帮助我吗?谢谢你的帮助。