2017-08-02 3 views
1

に応答からホストされた支払いページを解析する方法:私は第三者から1つの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> 

、私は名前の入力フィールドを解析しますResponseCipherは私のアンドロイドコードです。しかし、このホストされた支払いページからどのように取り出すべきですか?

答えて

2

JSoupライブラリを使用することをお勧めします。

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

そしてに解析する:たとえば

あなたはその応答を解析し、「ResponseCipher」の「値」属性を取得したい場合は、あなたが最初のレスポンスの端から「スクリプト」部分をカットしなければならない提出しました「値」属性を取得:

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