android - 如何从 android 中的响应解析托管支付页面

标签 android

在我使用来自第三方的一个 REST API 后,我得到以下托管支付页面作为响应:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>

</title>
    </head>
    <body>
        <form method="post" action="./spr.aspx" id="form1">
            <div class="aspNetHidden">
                <input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />
            </div>
            <div class="aspNetHidden">
                <input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="value" />
            </div>
            <div>
                <div id="PanelPleaseWait">
                    <div style="min-height: 10em; display: block; vertical-align: middle; text-align: center; padding-top: 100px;">
                        <h3>
        Processing, please wait...</h3>
    Please wait, your transaction is processing. Please don't hit back or stop.
                        <br />
                        <img src="images/bigrotation.gif" />
                    </div>
                </div>
            </div>
            <input name="ResponseCipher" type="hidden" id="ResponseCipher" value="cipher" />
        </form>
    </body>
</html>
<script type="text/javascript">
document.forms[0].action='http://website.in/';
document.forms[0].submit();
</script>

现在,我想在我的 android 代码中解析名称为 ResponseCipher 的输入字段。但是我应该如何从这个托管支付页面获取它呢?

最佳答案

我建议使用 JSoup图书馆。

例如,如果您想解析该响应并获取“ResponseCipher”字段的“value”属性,您应该首先从响应末尾剪切“脚本”部分:

source = source.substring(0,source.indexOf("<script"));

然后解析得到“value”属性:

Document document = Jsoup.parse(source, "UTF-8");
Elements input = document.select("input[name=ResponseCipher]");
String value = input.attr("value");

关于android - 如何从 android 中的响应解析托管支付页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45463152/

相关文章:

android - 在android html.fromHtml 中突出显示文本颜色

android - 是否可以在操作系统重启后立即运行我的 Android 应用程序?

android - 无法选择多张图片上传到 Android - Chrome 网络浏览器

android - 无法解析方法 setSupportActionBar(androidx.appcompat.widget.Toolbar)

android - 如何将相对布局停靠到屏幕底部

android - 在 AsyncTask 中跟踪文件下载的进度

android - UndeliverableException 与 rxJava2 和改造

android - 处理 Android 设备关闭(ISSUE : The intent is received only the first time)

java - 空对象引用上的 FFmpeg.execute.FFmpegExecuteResponseHandler

java - Android 进度对话框未关闭