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



我有一个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,这仅适用于开发阶段。

相关内容

最新更新