Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

SOLVED: HttpURLConnection Cannot set request property after connection is made

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();
List cookies = 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


This post first appeared on Stack Solved, please read the originial post: here

Share the post

SOLVED: HttpURLConnection Cannot set request property after connection is made

×

Subscribe to Stack Solved

Get updates delivered right to your inbox!

Thank you for your subscription

×