为了解决这个问题,我去过很多地方,但没有去做。
尝试SSL连接时“Android返回错误”“不受信任的服务器证书”。 https://google.cl/工作,但https://autoservicio.movistar.cl/不起作用: - / 我的项目:
package com.drawcoders.saldomovistarchile;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import javax.net.ssl.HostnameVerifier;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.scheme.PlainSocketFactory;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.ssl.SSLSocketFactory;
import org.apache.http.conn.ssl.X509HostnameVerifier;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.impl.conn.SingleClientConnManager;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;
public class SaldoMovistarChileActivity extends Activity {
TextView statusText;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
statusText = (TextView) findViewById(R.id.statusText);
login();
}
void login(){
try {
HostnameVerifier hostnameVerifier = SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER;
DefaultHttpClient client = new DefaultHttpClient();
SchemeRegistry registry = new SchemeRegistry();
SSLSocketFactory socketFactory = SSLSocketFactory.getSocketFactory();
socketFactory.setHostnameVerifier((X509HostnameVerifier)hostnameVerifier);
registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
registry.register(new Scheme("https", socketFactory, 443));
SingleClientConnManager mngr = new SingleClientConnManager(client.getParams(), registry);
DefaultHttpClient httpClient = new DefaultHttpClient(mngr, client.getParams());
HttpPost post = new HttpPost("https://autoservicio.movistar.cl/login/loginTop");
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("rut", "1000000"));
nameValuePairs.add(new BasicNameValuePair("dv", "0"));
nameValuePairs.add(new BasicNameValuePair("idRut", "10000000-0"));
nameValuePairs.add(new BasicNameValuePair("clave", "00000000"));
post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpClient.execute(post);
// HttpResponse response = client.execute(post);
HttpEntity entity = response.getEntity();
String responseText = EntityUtils.toString(entity);
statusText.setText("Finalizado!");
} catch (UnsupportedEncodingException e) {
statusText.setText("Error: " + e.getMessage().toString());
} catch (ClientProtocolException e) {
statusText.setText("Error: " + e.getMessage().toString());
} catch (IOException e) {
statusText.setText("Error: " + e.getMessage().toString());
}
}
}
谢谢:)
答案 0 :(得分:1)
看来(判断我的Android设备:Galaxy Nexus,Android 4.1.1)此版本未提供用于域 autoservicio.movistar.cl 的CA根证书Android版本,可能是4.1.1之前的版本。
对于您信任的网站,请尝试此处提供的解决方案:Trusting all certificates using HttpClient over HTTPS
答案 1 :(得分:1)
网站https://autoservicio.movistar.cl不会返回中间证书,因此客户端无法构建到受信任根的链。 Firefox也会出错。
此SSL检查程序显示仅返回服务器证书:
http://certlogik.com/ssl-checker/autoservicio.movistar.cl
缺少的中间证书就是这个:
CN = VeriSign第3类国际服务器CA - G3,OU = https://www.verisign.com/rpa使用条款(c)10,OU = VeriSign信任网络,O =“VeriSign,Inc。”,C = US
----- BEGIN CERTIFICATE ----- MIIGKTCCBRGgAwIBAgIQZBvoIM4CCBPzLU0tldZ + ZzANBgkqhkiG9w0BAQUFADCB yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW ZXJpU2lnbiBDbGFzcy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