下午好,正如标题中所说,我无法在我的 Android 应用程序中连接到我的球童驱动网站上的子域。我正在将应用程序的后端从 Heroku 迁移到我自己的 digitalocean droplet,并且该应用程序在使用 Heroku 时可以正常工作。
我得到的错误信息如下:
W/System.err: javax.net.ssl.SSLException: hostname in certificate didn't match: <sub.domain.com> != <domain.com> OR <domain.com>
W/System.err: at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:185)
W/System.err: at org.apache.http.conn.ssl.BrowserCompatHostnameVerifier.verify(BrowserCompatHostnameVerifier.java:54)
W/System.err: at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:114)
W/System.err: at org.apache.http.conn.ssl.AbstractVerifier.verify(AbstractVerifier.java:95)
W/System.err: at org.apache.http.conn.ssl.SSLSocketFactory.createSocket(SSLSocketFactory.java:388)
W/System.err: at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:165)
W/System.err: at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:164)
W/System.err: at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:119)
W/System.err: at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:360)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:555)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:487)
W/System.err: at org.apache.http.impl.client.AbstractHttpClient.execute(AbstractHttpClient.java:465)
相关的Android代码是:
try {
HttpClient client = new DefaultHttpClient();
final HttpPostHC4 post = new HttpPostHC4(url);
String json = "";
ArrayList<NameValuePair> nameValuePairs = new ArrayList<>();
for (Map.Entry<String, String> entry : valuePair.entrySet()) {
nameValuePairs.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
UrlEncodedFormEntityHC4 entity = new UrlEncodedFormEntityHC4(nameValuePairs, "UTF-8");
content = entity.getContent();
System.out.println(entity);
post.setEntity(entity);
final HttpResponse response = client.execute(post);
code = response.getStatusLine().getStatusCode();
responseText = EntityUtils.toString(response.getEntity());
} catch (Exception exc) {
exc.printStackTrace();
if (responseText != null) {
System.out.println(responseText);
}
}
这是我的 Caddyfile 的相关部分
sub.domain.com {
root /var/www/sub.domain.com/public
log /var/www/sub.domain.com/storage/logs/caddy-access.log
errors /var/www/sub.domain.com/storage/logs/caddy-error.log
fastcgi / /run/php/php7.0-fpm.sock php {
index index.php
}
rewrite {
r .*
ext /
to /index.php?{query}
}
}
我可以在我的网络浏览器中连接到子域,所以我真的不确定为什么会这样。我不太热衷于禁用主机名验证,所以我想知道是否有办法在 Caddy 端修复它。