2017-08-02 14 views
1

響應解析託管支付頁面我使用來自第三方的一個REST API後,我得到響應以下託管支付頁面:如何從Android中

<!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> 

現在,我想分析的輸入字段名ResponseCipher在我的android代碼中。但是,我應該如何從這個託管的付款頁面獲取它?

回答

2

我建議使用JSoup庫。

例如,如果你想解析響應並獲得「價值」,「ResponseCipher」屬性提交您應該削減爲先「腳本」部分,從響應的結束:

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

,然後解析到獲得「價值」屬性:

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