java - 如何从 Codename one 的 ConnectionRequest 获得来自 http 和不安全 https 站点的响应?Android 10 中的 http 和 https 问题(在 Google Pixel 中)
问题描述
我是 Codenameone 的新手,我在 Codenameone 的 ConnectionRequest API 中遇到了奇怪的问题,同时从安装了 anroid 10 的谷歌像素设备中的 https 站点获取响应。从 https 站点获取工作正常。
然而,在模拟器中它很好,并且在其他安卓版本低于 10 的设备上也很好。
这可能是什么解决方案,或者我在做什么?
这是我在设备中遇到的代码和错误
第一次尝试:
TextArea resultTextArea = new TextArea();
Button download = new Button("RUN");
download.addActionListener((e) -> {
ConnectionRequest cr = new ConnectionRequest(url, false);
SliderBridge.bindProgress(cr, progress);
NetworkManager.getInstance().addToQueueAndWait(cr);
if (cr.getResponseCode() == 200) {
String resultString = "";
try {
byte[] initialArray = cr.getResponseData();
resultString = new String(initialArray);
resultTextArea.setText(resultString);
} catch (Exception eee) {
resultString = "Error => " + resultString + eee.getMessage();
}
System.out.println(resultString);
}
});
第二次尝试:其中 url = http://192.168.2.100:8084/semms-webservice/rest/device/test/users
public void testURLConnectionResponse(String url) {
ConnectionRequest request = new ConnectionRequest();
request.setContentType("application/json");
request.setUrl(url);
request.setHttpMethod("GET");
TextArea resultTextArea = new TextArea();
String result = "";
result = "RESPONSE CODE :- " + request.getResponseCode() + " --- ";
Response<String> resultx = Rest.put(url).getAsString();
result += resultx.getResponseData();
resultTextArea.setText(result);
Form hi = new Form("Test Connection Response", new BoxLayout(BoxLayout.Y_AXIS));
Button mainFormButton = new Button("Back To Main Form");
mainFormButton.addActionListener((e) -> mainForm());
mainFormButton.setRippleEffect(true);
hi.add(mainFormButton);
hi.show();
// request will be handled asynchronously
NetworkManager.getInstance().addToQueue(request);
}
enter code here
解决方案
我假设这在模拟器中有效并且在设备上失败了?
发生这种情况的原因有多种,但在这种情况下,它看起来像一个子网 IP 地址。您正在尝试从可能位于运营商网络上的设备连接到内部公司 URL。尝试通过浏览器连接到 URL 并查看设备是否可以访问它。
作为一种解决方法,您可以连接到公司内部 wifi 并查看服务器是否可以访问。
推荐阅读
- azure-devops - Widget/Chart needed in Azure DevOps for Work Done Analysis
- c++ - 带有负整数的十六进制 sprintf 的行为
- php - 使用文档块在 PHP 中记录抽象工厂方法返回类型
- java - Eclipse for java,Ant 期间包 org.junit 不存在
- c++ - C++:存储旧 int 句柄和新句柄之间的映射
- r - 将前缀/后缀添加到列表中的多列 dfs
- docker - 如何从 ssh 连接后面的私有注册表中提取 Kubernetes 集群中的 docker 映像
- angular - 当以反应形式按下回车键时,mat-autocomplete 会触发 displayFn
- python - 如何在python中列出目录中的图像路径?
- rust - Rust 配置箱和多态类型