2010-07-13 113 views
1

作爲我論文論文的一部分,我構建了一個「機器人」,用於抓取C語言程序的官方論壇,並搜索常見問題以發佈回覆。我必須模擬登錄才能發佈相應的回覆。登錄形式如下:使用Java登錄到vbulletin論壇

- 登錄表單 - 形式的行動= 「?login.php中做=登錄」 方法= 「郵報」 的onsubmit = 「md5hash(vb_login_password,vb_login_md5password,vb_login_md5password_utf,0)」 > script type =「text/javascript」src =「clientscript/vbulletin_md5.js?v = 385」> table cellpadding =「0」cellspacing =「3」border =「0」> tr> td class =「 smallfont」樣式= 「空白:NOWRAP;」>Όνομαχρήστη TD>

TD類= 「smallfont」 NOWRAP = 「NOWRAP」>ΑυτόματηΣύνδεση /TR> TR> TD類= 「smallfont」>Κωδικός TD> TD> /TR> /TABLE>

INPUT TYPE = 「隱藏」 名稱= 「S」 值= 「」/> INPUT TYPE = 「隱藏」名稱=「securitytoken」value =「guest」/> input type =「hidden」name =「do」value =「login」/> input type =「hidden」name =「vb_login_md5password」/> input type =隱藏」的名字=‘vb_login_md5password_utf’/> /FORM> ! - /登錄窗體 - >

我已經明白,我需要MD5哈希密碼,但我不能任何登錄。我使用POST方法,我準備內容執行以下操作:

content = "do=login&url=login.php" + "&vb_login_md5password=" + md5_pass+ "&vb_login_md5password_utf="+ md5_pass + "&s=&securitytoken=guest&vb_login_username=" + UserName + "&vb_login_password=" + PassWprd; 

我再發做以下的角逐:

urlConnection = (HttpURLConnection)(new URL(targetUrl).openConnection()); 

     // Specifying that we intend to use this connection for input 
     urlConnection.setDoInput(true); 

     // Specifying that we intend to use this connection for output 
     urlConnection.setDoOutput(true); 

     // Specifying the method of HTTP request which is POST 
     // throws ProtocolException 
     urlConnection.setRequestMethod("POST"); 

     // Specifying the content type of our post 
     urlConnection.setRequestProperty("Content-Type", POST_CONTENT_TYPE); 
     urlConnection.setRequestProperty("Content-length",String.valueOf (content.length())); 
     // urlConnection.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows 98; DigExt)"); 

     // Prepare an output stream for writing data to the HTTP connection 
     // throws IOException 
     dataOutputStream = new DataOutputStream(urlConnection.getOutputStream()); 
     dataOutputStream.writeBytes(content); 

儘管如此,我無法登錄。我相信我發送的表單有問題,但我找不到。任何幫助將不勝感激,因爲我必須在幾天內完成該計劃。

回答

0

我認爲最好的辦法是,如果你第一次嘗試看到你的http請求等於瀏覽器在正常登錄時創建的請求。

爲此,您可以在Firefox(https://addons.mozilla.org/de/firefox/addon/3829/)中安裝Live HTTP Header插件 - 這將允許您查看瀏覽器登錄請求的樣子。

在java方面,toString()方法被覆蓋,並且應該顯示完整的頭文件afaik。如果沒有,只需比較內容字符串並確保您確實設置了所有正確的標題。

+0

我做了你所說的,我找到了正確的表單和正確的POST登錄鏈接,最後它工作。感謝您的幫助:P – fysob 2010-07-13 16:15:23

+0

@fysob您可以使用您的代碼發佈答案嗎?我試圖在vbulletin論壇上完成同樣的事情。 – localhost 2014-11-25 05:12:48

1

我不會嘗試僞造HTTP請求,而是建議您依賴虛擬Web客戶端,如HtmlUnit。它允許你在更高的層次上進行操作,而不是試圖用正確的元素僞造一個HTTP查詢,你「只是」必須用正確的值填充表單。