首页 > 解决方案 > 如何从 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

在此处输入图像描述

标签: javaioshttpsconnectioncodenameone

解决方案


我假设这在模拟器中有效并且在设备上失败了?

发生这种情况的原因有多种,但在这种情况下,它看起来像一个子网 IP 地址。您正在尝试从可能位于运营商网络上的设备连接到内部公司 URL。尝试通过浏览器连接到 URL 并查看设备是否可以访问它。

作为一种解决方法,您可以连接到公司内部 wifi 并查看服务器是否可以访问。


推荐阅读