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

时间:2017-08-02 14:04:42

标签: 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的输入字段。但是我应该如何从此托管付款页面获取它?

1 个答案:

答案 0 :(得分:2)

我建议使用JSoup库。

例如,如果您要解析该响应并获得“ResponseCipher”的“value”属性,则应首先从响应结束处删除“script”部分:

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");