我尝试使用HttpURLConnection登录路由器,为此我使用以下代码:
httpCon = (HttpURLConnection) getURL().openConnection();
httpCon.setRequestProperty("User-Agent", getUserAgent());
httpCon.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
httpCon.setRequestProperty("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
httpCon.setRequestProperty("Accept-Encoding", "gzip, deflate");
httpCon.setRequestProperty("Connection", "keep-alive");
httpCon.setRequestProperty("Host", "192.168.1.1");
httpCon.setRequestMethod(httpMethod.value());
httpCon.connect();
for (String string : httpCon.getHeaderFields().keySet()) {
System.out.println(httpCon.getHeaderField(string));
}
OutputStreamWriter out = new OutputStreamWriter(httpCon.getOutputStream());
out.write(getData());
eout.close();
但我收到以下消息:
bytes
HTTP/1.1 200 OK
text/html
max-age=0, must-revalidate
Apache
Keep-Alive
6190
no-cache
当我使用Firefox登录时,我发现在发出POST
请求时,我会收到一个" set-cookie",但是HttpURLConnection
我没有。{有什么想法来解决这个问题?