gpt4 book ai didi

android - 在 Android 中使用自定义版本的 App Engine 应用程序

转载 作者:太空宇宙 更新时间:2023-11-03 12:52:46 28 4
gpt4 key购买 nike

我正在尝试在 Android 应用程序中使用非默认的 App Engine 应用程序版本。默认的 App Engine 应用程序版本是 1,我已经上传了一个新版本 2 并想使用 Android 应用程序对其进行测试。

应用实例的默认根路径如下:

xxx.appspot.com

这两个实例都可以(或应该)使用:

https://1.xxx.appspot.com    // version 1
https://2.xxx.appspot.com // version 2

第一个问题是通过浏览器进行测试。在 Chrome 中,您无法对其进行测试,因为出现错误消息 Your connection is not private。看起来像 *.appspot.com 的证书问题:

NET::ERR_CERT_COMMON_NAME_INVALID

您可以使用 Firefox 解决此问题,并将给定站点添加为可信站点。因此假设第二个版本是通过浏览器测试的,是时候使用 Android 应用程序对其进行测试了。

我更改了端点根 URL,将新 URL 传递给构建器:

builder.setRootUrl(https://2.xxx.appspot.com);

失败:

java.io.IOException: Hostname '2.xxx.appspot.com' was not verified
at com.android.okhttp.Connection.upgradeToTls(Connection.java:1026)
at com.android.okhttp.Connection.connect(Connection.java:963)
at com.android.okhttp.internal.http.HttpEngine.connect(HttpEngine.java:405)

快速搜索 SO 有一个快速而肮脏的解决方案(我不会在生产中使用它,甚至不会测试应用程序。当然应该执行主机名检查,例如使用默认验证器,然后如果默认返回 false使用我的后备验证器):

HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});

最终结果:

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.newExceptionOnError(ProGuard:113)
at com.google.api.client.googleapis.services.json.AbstractGoogleJsonClientRequest.set(ProGuard:40)
at com.google.api.client.googleapis.services.AbstractGoogleClientRequest$1.interceptResponse(ProGuard:312)

无论我使用哪个版本,它都以 404 结束。唯一有效的 URL 是 https://xxx.appspot.com 我确定我尝试调用的方法存在在端点上,因为我可以使用 Firefox 调用它。

关于如何使用 Android 应用程序测试新的 App Engine 应用程序版本有什么建议吗?证书验证失败是一个错误,还是 *.appspot.com 仅匹配 xxx.appspot.com 但不匹配 x 的正确行为.xxx.appspot.com?

最佳答案

显然解决方案在文档中:

Please note that in April of 2013, Google stopped issuing SSL certificates for double-wildcard domains hosted at appspot.com (i.e. ..appspot.com). If you rely on such URLs for HTTPS access to your application, please change any application logic to use "-dot-" instead of ".". For example, to access version "1" of application "myapp" use "https://1-dot-myapp.appspot.com" instead of "https://1.myapp.appspot.com." If you continue to use "https://1.myapp.appspot.com" the certificate will not match, which will result in an error for any User-Agent that expects the URL and certificate to match exactly.

简而言之,我必须将 2. 替换为 2-dot-

关于android - 在 Android 中使用自定义版本的 App Engine 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27475447/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com