为什么我使用HttpURLConnection获取null cookie?

时间:2017-12-16 00:31:41

标签: java session-cookies

我尝试使用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我没有。{有什么想法来解决这个问题?

0 个答案:

没有答案