如何在改造中解析响应体的响应中的html标记

时间:2017-08-23 06:23:27

标签: android retrofit2

我的代码如下所示:

   private void testInfo() {
        if (InternetConnection.checkConnection(LogInActivity.this)) {
            Observable<ResponseBody> results = RetroClient.getApiService()
                    .testInfo("Basic NTcyODQ4MDc0NzEzNTIwOToxMjhiNTNkMS1iMTc2LTQxOTEtYWJmYS1hN2RhYjIzYmFjMzk=", "application/x-www-form-urlencoded",
                            "John Q. Test", "Visa", "4747474747474747", 12, 25, 999, "123 A. Street",
                            "Orem", "UT", "84058", "USA", "4355824", "ACkwlGTtMOGNlwtLY2GIsi/MgC5bgDOQIVzPFKzapIEcnUR7XEvTfeYLeVswApKH+vW+1rgO7PwJahABSrtYgC6ZmkOTxywIb24mdyefTZpOu+h9iDdu/SYcDnBcwf/sjcntYBLPCL5+gPLCpu9YpItDhb055zf9bNDWEGdoLRbl6BPVPbYCEQH9et72KxgnPZHA3Oe05IrRiy22pP8HAzpzss8c37MjEOQB5tbfkuDUCj1pfCohsQ74JBDgc0ntG+rpv7ljFElCxO95FyVYkGhIwaMQWaplwhpWqJIIw9JRL0IRTZG+ml1QzJBgdNHyKJXJmH9Gh/yVzXU4U9gyY6d3ObUYT0ODjNwnEIAc1XSOFd+WE5XklitZynuo4MgghWfZpMl0ChofstLS5e/Np7RF0xJe8WGAAV4Jdku84mnrt/42YRW2yzpUOpKI8+VddlRDKRsmvkei8gY4yjxINocMUfnzPBmsecgW8EVO1nIBpKLW36wLJ7Bawy6MA7wULO5TyP5j9ksdn6Y5IOOT+rpiJc6+OUJZZ0I7ef6qWuE=");
//            showProgressBar();
            results.subscribeOn(Schedulers.io()).observeOn(AndroidSchedulers.mainThread())
                    .subscribe(new Subscriber<ResponseBody>() {
                        @Override
                        public void onCompleted() {
                            unsubscribe();
                        }

                        @Override
                        public void onError(Throwable e) {
//                            hideProgressBar();
                            Toast.makeText(LogInActivity.this, e.getMessage(), Toast.LENGTH_LONG).show();
                        }

                        @Override
                        public void onNext(ResponseBody response) {
                            Log.d(TAG, "onNext: " + response.string());
                        }
                    });
        } else {
            Toast.makeText(LogInActivity.this, R.string.string_internet_connection_warning, Toast.LENGTH_LONG).show();

        }
    }

现在为此,我得到以下作为我的回复:

<!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">
<input type="hidden" name="__VIEWSTATE" id="__VIEWSTATE" value="" />

<input type="hidden" name="__EVENTVALIDATION" id="__EVENTVALIDATION" value="k2sKy+QLc68jCgZVuadfy2ONS4SO3c0" />
    <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="6s31abi0RZUSAw3Iwk0db9irVWKTi2+UtpSVTUE7DKlhWqLd1WBlQ==" /></form>
</body>
</html>
<script type="text/javascript">
document.forms[0].action='http://krl.in/';
document.forms[0].submit();
</script>

在这里,我想要的是,我想访问ID为value的输入ResponseCipher。我该怎么做才能实现这个目标?

1 个答案:

答案 0 :(得分:1)

Jsoup是一个库,允许您解析String中的大量HTML标记/属性。 只需解析您的欲望输入ID,您也应该访问该值。

查看以下来源。