我的应用程序存在一些问题,我认为这是一个问题,客户端通过公共wifi连接进行连接,解决当前的DNS和应用程序,将其视为“中间人”# 39;从而引发代码错误并导致错误报告 "
javax.net.ssl.SSLException: hostname in certificate didn't match: !="
我已在下面的单独功能中实施了URL和IP检查,但我很乐意调查任何最佳实践'处理开放WIFI(如OpenBT或Mcdonalds wifi)的标准,需要登录/支付购买,但注册为真正的WiFi连接。
以下是最初标记错误的JSON请求代码示例。下面是一个检查URL功能,用于检查URL和正确的IP,以查看它们是否可以相互解决。
感谢您花时间帮我解决此问题!
protected static jsonHandler jhJSONRequest(String strType, Cursor c, Context myContext) throws Exception {
jsonHandler myReturnValues = jhTableToJSON(strType, c, myContext);
String strPath = "https://www.******.co.uk/****/*****/******/json_collector.ashx?";
strPath += "dttablet=" + ES_Functions.lngGetCurrentDateTime(myContext);
strPath += "&engid=" + intEngineerID(myContext);
strPath += "&tabletid=" + ES_Functions.strUniqueID(myContext);
strPath += "&key=" + strJSONKey;
strPath += "&" + strType.toLowerCase() + "=1";
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httpost = new HttpPost(strPath);
StringEntity se = new StringEntity(myReturnValues.strJSON);
httpost.setEntity(se);
httpost.setHeader("Accept", "application/json");
httpost.setHeader("Content-type", "application/json");
HttpResponse response = httpclient.execute(httpost);
if (response.getStatusLine().getStatusCode() != 200) {
throw new Exception("JSON Response Failed");
} else {
return myReturnValues;
}
}
protected static boolean checkURL(String strUrl, String strIP)
{
ThreadPolicy tp = ThreadPolicy.LAX;
StrictMode.setThreadPolicy(tp);
boolean portReached = false;
try {
URL url = new URL(strUrl);
InetAddress address = InetAddress.getByName(url.getHost());
InetAddress addr = InetAddress.getByName(strIP);
if(address.equals(addr))
{
SocketAddress sockaddr = new InetSocketAddress(addr, 80);
// Create an unbound socket
Socket sock = new Socket();
// This method will block no more than timeoutMs.
// If the timeout occurs, SocketTimeoutException is thrown.
int timeoutMs = 2000; // 2 seconds
sock.connect(sockaddr, timeoutMs);
portReached = true;
}
}
catch(Exception e){
Log.w(TAG, "--- NOTE - COULD NOT RESOLVE PORT ON INET SOCKET ---");
}
return portReached;
}