Maseed:
I get the Exception Cannot set request property after connection is made
while trying to load cookies back into the request. Watched different suggested solutions but nothing worked. Here is my code.
URL url = new URL(URL_STRING);
HttpURLconnection connection = (HttpURLConnection) url.openConnection();
con.setRequestProperty("User_Agent", System.getProperty("http.agent"));
java.net.CookieManager cm = new java.net.CookieManager();
Map> headerFields = connection.getHeaderFields();
Listcookies = headerFields.get(COOKIES_HEADER);
if (cookies != null) {
for (String cookie : cookies) {
cm.getCookieStore().add(null, HttpCookie.parse(cookie).get(0));
}
}
if (cm.getCookieStore().getCookies().size() > 0) {
connection.setRequestProperty("Cookie", TextUtils.join(";", cm.getCookieStore().getCookies()));
}
NOTE: This whole code is running in the doInBackground method of the AsyncTask if it is the point of interest.
And requested php file has only one line of code. setcookie("cookie[one]", "cookieone");
Posted in S.E.F
via StackOverflow & StackExchange Atomic Web Robots
This Question have been answered
HERE