【发布时间】:2017-05-04 14:36:19
【问题描述】:
我已按照this guide 生成自签名 SSL 证书, 我成功地制作了 .cer 和 .bks。然而:
使用设备设置安装 .cer 文件是否与使用 CODE 安装 .bks 文件相同?
我的手机浏览器毫无问题地接受我的网站时遇到问题。但是,当我运行我的应用程序以查询来自相同 website/myservice.ASMX 的服务的肥皂请求时,它会给出“主机名未验证”,如果使用 trustmaster “接受所有主机和证书”,我会收到错误 405
访问网站的代码:
SoapObject Request = new SoapObject(NAMESPACE, method);
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
envelope.dotNet = true;
PropertyInfo password = new PropertyInfo();
password.setName(ID);
password.setValue(pass);
password.setType(String.class);
Request.addProperty(password);
envelope.setOutputSoapObject(Request);
HttpTransportSE androidHttpsTransport = new HttpTransportSE("https://"+MAIN_REQUEST_URL+":"+sPORT+SERVICELOCATION);
makeFileOffline(androidHttpsTransport.getHost() +"\n"+ SERVICELOCATION,"AgriHTTP" );
try {
//FakeX509TrustManager.allowAllSSL();<< When enabled it gives 405
androidHttpsTransport.call(NAMESPACE+method, envelope);
SoapPrimitive resultsString = (SoapPrimitive) envelope.getResponse();
String webServiceResult = resultsString.toString();
} catch (IOException e) {
Log.d(e.toString(),"LogCat" );
e.printStackTrace();
} catch (XmlPullParserException e) {
e.printStackTrace();
}
【问题讨论】:
-
Log.d(e.toString(),"LogCat" );应该是Log.e("LogCat", e.getMessage(), e);更多信息:developer.android.com/reference/android/util/… -
考虑使用 volley 发出 api 请求。这是执行此操作的指南,developer.android.com/training/volley/index.html