2011-06-02 22 views
2

我的問題是與此類似: HTTPclient POST with problematic web site的Android DefaultHTTPClient於JavaScript驅動的網站填寫表格以郵寄請求

我曾經篡改數據以找出所有的請求通過客戶端和服務器的準備。

我最初執行get請求來加載頁面並獲取動態生成的字段值。然後,我爲相關表單的所有輸入字段創建了命名值對的列表並執行了post req,但它將我重定向到一個錯誤頁面。

我試着設置cookie並在所有可能的方式處理sslfactory建議在計算器:

,但它不是爲我工作。

我不知道什麼問題,我甚至沒有在日誌中出現任何錯誤。 我在這個問題上花了幾天時間。

+0

我終於自己解決了這個問題。使用HTTPCLeint本身。我沒有正確提取hideen字段值。 – droidster 2011-07-06 03:14:51

+0

您可以將您的解決方案作爲答案發布,以便我們可以從未答覆列表中獲得此答案嗎?謝謝。 – 2011-07-12 14:48:11

回答

3

該解決方案使用相同的HttpClient而不需要維護cookie或其他任何東西。 首先查找所有請求(獲取或發佈)使用篡改數據的請求。然後將解壓後動態生成的隱藏字段的值:

public static String getPage(String sURL) throws HttpException { 
    HttpGet method = new HttpGet(sURL); 

    // method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, 
    // new DefaultHttpMethodRetryHandler(3, false)); 

    try { 
     /* 
     * int statusCode = client.execute(method); if (statusCode != 
     * HttpStatus.SC_OK) { System.err.println("Method failed: " + 
     * method.getStatusLine()); } 
     */HttpResponse res; 
     res = client.execute(method); 

     BasicResponseHandler myHandler = new BasicResponseHandler(); 
     String content = myHandler.handleResponse(res); 
     //extract dynamic parameters here 
     return content; 
    } catch(...) { 

    } 
} 

然後對後使用此方法:

public static String postPage1(list of parameters to be passed in the post form) throws HttpException { 
    BasicNameValuePair[] data = { 
     new BasicNameValuePair("field name", "param1"), 
     ...... 
    }; 
    HttpPost post = new HttpPost(sURL); 

    // post.setRequestBody(data); 
    try { 
     post.setEntity(new UrlEncodedFormEntity(Arrays.asList(data))); 

     HttpResponse res; 
     res = client.execute(post); 
     int statusCode; 

     BasicResponseHandler myHandler = new BasicResponseHandler(); 
     String content = myHandler.handleResponse(res); 
     return content; 
    } catch (...) { 

    } 
} 

就是這樣。