首先,您必須決定是否要在瀏覽器或代碼中執行此操作。
在代碼中,你將需要大概自動化的HTTP POST是這樣的:
// Start up your network connection
URL url = new URL("http://www.asdf.com/someFormSubmissionPage);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoInput(true);
String userInfo = "username=bob&password=pass";
connection.setRequestProperty("Content-Length", "" + userInfo.length());
connection.setDoOutput(true);
// Send the actual data
OutputStream out = connection.getOutputStream();
out.write(userInfo.getBytes(UTF_8));
// Flush everything to the destination
out.flush();
out.close();
BufferedReader connectionReader = new BufferedReader(new InputStreamReader(connection.getInputStream(), UTF_8));
String responseLine;
// Collect the entire response
while ((responseLine = connectionReader.readLine()) != null)
response.append(responseLine);
在這一點上,你可以做一些事情的反應,也許保存服務器發回給你一個cookie,或者任何你想要的。
作爲替代方案,你可以打開一個網頁視圖並給它像http://www.asdf.com/someFormSubmissionPage?username=bob&password=pass
地址這將出演TUP與登錄的用戶的瀏覽器。
的someFormSubmissionPage
會做一個被發現view source
在瀏覽器中查看實際站點的登錄頁面。用戶名/密碼的詳細信息也可以通過這種方式找到。
謝謝!這正是我需要的。關於答案的最後一部分的最後一個問題雖然我無法找到此表單提交頁面/用戶名和密碼的變量。任何其他方式我可以去找到這些? – Andrew 2013-03-01 06:43:11
您必須能夠看到它期望的數據類型以及它發送的位置。通常,當您在網頁上填寫表單時,您可以執行右鍵單擊 - >查看源代碼。在這一點上,你真的必須搜索字段名稱,形成行動來獲取你需要的數據。你可以發佈表單網址嗎? – Shellum 2013-03-01 06:54:43
我看到了,網址如下:http://www.powerbot.org/community/index.php?app=core&module=global§ion=login – Andrew 2013-03-01 07:00:53