我正在尝试将Android应用程序移植到IOS平台.我从位于Apache Tomcat服务器中的服务获取数据,最近他们在服务上添加了安全性.安全概述是
Android版本没有问题.在添加安全性之前,我正在执行简单的http请求,但现在我需要使用我的凭据执行POST请求,因此我总是收到error.html.我远不是网络编程方面的专家.
这是Android http客户端设置代码:
if(httpClient==null)
{
DefaultHttpClient client = new DefaultHttpClient();
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
trustStore.load(null, null);
SSLSocketFactory sf = new MySSLSocketFactory(trustStore);
sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
SchemeRegistry registry = new SchemeRegistry();
registry.register(new Scheme("https", sf, 8443));
mgr = new ThreadSafeClientConnManager(client.getParams(), registry);
int timeoutConnection = 5000;
HttpConnectionParams.setConnectionTimeout(client.getParams(), timeoutConnection);
// Set the default socket timeout (SO_TIMEOUT)
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 7000;
HttpConnectionParams.setSoTimeout(client.getParams(), timeoutSocket); …Run Code Online (Sandbox Code Playgroud)