我有一个更新,然后项目无法连接到 Web 服务。(它落在 catch 块上)

I had an update, then project couldn't connect to Web Services.( It drops on catch block)

我有 Android Studio 的更新。完成后,我遇到了 Ksoap2 3.6.2 的问题。当我调试时,它总是在 catch 块中。

为了解决这个问题,我卸载了 Ksoap2,然后重新安装。但它仍然无法连接到 Web 服务。我该如何解决这个问题?

SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
        SoapEnvelope.VER11);
        envelope.dotNet = true;
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
        String resTxt = null;
        try {    
            androidHttpTransport.call(SOAP_ACTION + webMethName, envelope);// 1.Step and then goes to catch block
            SoapPrimitive response = (SoapPrimitive) envelope.getResponse();
            resTxt = response.toString();
        } catch (Exception e) {//problem is here
            e.printStackTrace();
            result.Success = 0;
            result.Message = "Error!!!" + e.getMessage();
            return result;
        }

发生此问题是因为在 Android 9 上默认限制明文流量 (http)。您需要做的是添加到您的清单:

<application
     android:usesCleartextTraffic="true"

您应该避免在生产中使用 http,这仅适用于开发阶段。