我无法从服务器获取浏览器Cookie。我为CookieManager
和URLConnection
CookiePolicy
尝试了HttpClient
,但这些都没有效果。每次我尝试时,都会返回一个带有空会话ID的标题,以及来自网站的消息:
此系统需要使用HTTP cookie来验证授权信息。我们的系统检测到您的浏览器已禁用HTTP Cookie,或者不支持它们。
以前有人有这样的问题吗?
以下是我的一些代码。非常感谢你!
CookieManager manager = new CookieManager();
manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded");
connection.setRequestProperty("Server", "Oracle-Application-Server-11g");
connection.setRequestProperty("Content-Length", "" +Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "en-US");
connection.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.4 (KHTML, like Gecko) Chrome/22.0.1229.79 Safari/537.4"); connection.setRequestProperty("Accept","text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
connection.setUseCaches (false);
connection.setDoInput(true);
connection.setDoOutput(true);
//System.out.print(cookieHeader.toString());
//Send request
DataOutputStream wr = new DataOutputStream (connection.getOutputStream ());
wr.writeBytes(urlParameters);
wr.flush ();
wr.close ();