是否可以在异常之前读取答案?

发布于 2024-10-30 05:18:32 字数 191 浏览 4 评论 0原文

我正在开发一个项目,其中 Android 应用程序与 PHP 服务器(WAMP)进行通信,其中实现了一些方法。我们使用 XMLRPC 来处理客户端对服务器方法的调用。无论如何,即使一切都发生得很好,当 java 尝试读取答案时会抛出异常。所以我想知道在java抛出异常之前是否有任何方法可以读取或保存服务器的响应(这并不真正相关)?

预先感谢您的帮助!

I'm working on a project where an android application is communicating with a PHP server (WAMP) where some methods are implemented. We're using XMLRPC to handle client calls to server's methods. Anyway, even though everything happens fine, an exception is thrown when java tries to read the answer. So I would like to know if there is any way to read or save the server's response before java throws the exception (which is not really relevant) ?

Thanks in advance for your help !

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

野味少女 2024-11-06 05:18:32

通常的方法是在代码中捕获并处理此未经检查的异常。如果你没有抓住它,就会导致应用程序停止。

将导致异常的代码段包装到 try/catch 语句中。这应该允许您的申请继续,并且您应该能够保留和处理响应。

The usual approach is to catch and handle this unchecked exception in your code. If you don't catch it, it will cause the application to stop.

Wrap the piece of code that causes the exception into a try/catch statement. This should allow you application to continue and you should be able to keep and process the response.

暮光沉寂 2024-11-06 05:18:32

我已经设置了一个 try/catch 语句,如您所见:

Integer result2 = null;
 try {
     Object[] dataParams = new Object[]{bytes, date, login};
     result2 = ((Integer) client.execute("storeData", dataParams)).intValue();
     System.out.println(result2.toString());
 } catch (Exception ex)
 {
     ex.printStackTrace();
 }

storeData 方法应该返回一个 int。但当我遇到异常时,我看不到该响应。

这是我收到的错误:[Fatal Error] :1:1: Content is not allowed in prolog.

我认为这是由于 xml 响应中存在一些错误字符,所以这就是我想要的原因得到这个回应!

I do already set up a try/catch statement as you can see :

Integer result2 = null;
 try {
     Object[] dataParams = new Object[]{bytes, date, login};
     result2 = ((Integer) client.execute("storeData", dataParams)).intValue();
     System.out.println(result2.toString());
 } catch (Exception ex)
 {
     ex.printStackTrace();
 }

The storeData method is supposed to return an int. But as I get an exception, I can't see that response.

This is the error I get : [Fatal Error] :1:1: Content is not allowed in prolog.

I assume it's due to some bad characters in the xml response so that's why I'd like to get this response !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文