为什么当我可以实际输入提供 JSON 的 http 时,响应代码始终为 0?

问题描述 投票:0回答:1

我正在尝试将我的 Android Studio 应用程序连接到网站以拉取和读取 JSON,但我总是得到响应代码 0。我尝试使用订阅作为绝望的措施,因为仅使用 GET 或 POST 甚至没有给我响应代码,任何想法?我知道网址已打开,因为我可以在任何浏览器上访问它,但程序不想与它交互,我将不胜感激任何帮助

            HttpServiceClass httpServiceClass = new HttpServiceClass(HttpURL);
            httpServiceClass.ExecutePostRequest()
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Observer<String>() {
                        public void onSubscribe(Disposable d) {
                        }
                        public void onNext(String response) {
                            if (httpServiceClass.getResponseCode() == 0) {
                                Log.i("Error", "No tienes Conexion a Internet");
                                Error = "S";
                            } else if (httpServiceClass.getResponseCode() == 200) {
                                FinalJSonResult = httpServiceClass.getResponse();
java android kotlin http
1个回答
0
投票

感谢所有回答的人,结果我只需要跳过网址上的 SSL 证书,所以我添加了一个 TrustManager 并修复了它。

© www.soinside.com 2019 - 2024. All rights reserved.