List of usage examples for java.net CookieManager CookieManager
public CookieManager(CookieStore store, CookiePolicy cookiePolicy)
From source file:WebClient.java
public static void main(String[] args) throws Exception { CookieStore store = new MyCookieStore(); CookiePolicy policy = new MyCookiePolicy(); CookieManager handler = new CookieManager(store, policy); CookieHandler.setDefault(handler); URL url = new URL("http://localhost:8080/cookieTest.jsp"); URLConnection conn = url.openConnection(); InputStream in = conn.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(in)); String input;/*from w w w . j a va 2 s . c o m*/ while ((input = reader.readLine()) != null) { System.out.println(input); } reader.close(); }
From source file:jmc.util.UtlFbComents.java
public static void getComentarios(Long idContenido, Long numComents) throws JMCException { File f = null;//w w w . j a v a2s . co m try { Properties props = ConfigPropiedades.getProperties("props_config.properties"); CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); URL ur = new URL("http://graph.facebook.com/comments?id=" + Contenido.getContenido("Where cont_id = '" + idContenido + "'").get(0).getEnlaceURL() + "&limit=" + numComents + "&filter=stream"); HttpURLConnection cn = (HttpURLConnection) ur.openConnection(); cn.setRequestProperty("user-agent", props.getProperty("navegador")); cn.setInstanceFollowRedirects(false); cn.setUseCaches(false); cn.connect(); BufferedReader br = new BufferedReader(new InputStreamReader(cn.getInputStream())); String dirTempHtml = props.getProperty("archive_json") + "/"; File fld = new File(dirTempHtml); boolean creado = fld.exists() ? true : fld.mkdir(); if (creado) { String archFile = idContenido + ".json"; String archivo = dirTempHtml + archFile; String linea = null; f = new File(archivo); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); while ((linea = br.readLine()) != null) { bw.append(linea); } bw.close(); cn.disconnect(); List<Fbcoment> lfb = Convertidor.getFbcomentObjects(idContenido, archivo); Fbcoment.actComents(idContenido, lfb); } else { cn.disconnect(); } } catch (IOException e) { throw new JMCException(e); } }
From source file:gmusic.api.comm.HttpUrlConnector.java
public HttpUrlConnector() { CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); }
From source file:net.qiujuer.common.okhttp.Http.java
public static void enableSaveCookie(Context context) { getClient()/* w w w . j a v a 2s . c o m*/ .setCookieHandler(new CookieManager(new PersistentCookieStore(context), CookiePolicy.ACCEPT_ALL)); }
From source file:fr.cph.stock.android.web.Connect.java
protected Connect() { this.cookieManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); this.client = new MyHttpClient(); }
From source file:com.jaspersoft.android.jaspermobile.network.cookie.CookieHandlerFactory.java
@NonNull public CookieHandler newStore(@NonNull Context context) { WebViewCookieStore webViewCookieStore = createWebViewCookieStore(context); java.net.CookieStore cookieStore = new PersistentCookieStore(context); CookieMapper cookieMapper = new CookieMapper(); org.apache.http.client.CookieStore apacheStore = new ApacheCookieStore(cookieStore, cookieMapper); AppCookieStore appCookieStore = new AppCookieStore(webViewCookieStore, cookieStore, apacheStore); CookieHandler defaultCookieManager = new CookieManager(appCookieStore, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(defaultCookieManager); return defaultCookieManager; }
From source file:com.example.administrator.datarequest.ningworld.NoHttp.java
/** * Initialization NoHttp, Should invoke on {@link Application#onCreate()}. * * @param application {@link Application}. *//* ww w .j a v a2 s .c om*/ public static void init(Application application) { if (sApplication == null) { sApplication = application; PRNGFixes.apply(); sCookieHandler = new CookieManager(DiskCookieStore.INSTANCE, CookiePolicy.ACCEPT_ALL); } }
From source file:com.jamfsoftware.jss.healthcheck.controller.HTTPController.java
public String doGet(String URL) throws Exception { CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); URL obj = new URL(URL); //Relax host checking for Self Signed Certs HttpURLConnection con = (HttpURLConnection) obj.openConnection(); TrustModifier.relaxHostChecking(con); //Setup the Connection. con.setRequestMethod("GET"); con.setRequestProperty("User_Agent", USER_AGENT); Base64 b = new Base64(); String encoding = b.encodeAsString((username + ":" + password).getBytes()); con.setRequestProperty("Authorization", "Basic " + encoding); int responseCode = con.getResponseCode(); LOGGER.debug("Sending 'GET' request to URL : " + URL); LOGGER.debug("Response Code : " + responseCode); //Get the response BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine;/* w w w. j ava 2 s.c o m*/ StringBuilder response = new StringBuilder(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); }
From source file:jmc.util.UtlFbComents.java
public static void getURLComentarios(String url, Long numComents) throws JMCException { File f = null;// w w w. ja v a 2 s.c o m try { Properties props = ConfigPropiedades.getProperties("props_config.properties"); CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); URL ur = new URL( "http://graph.facebook.com/comments?id=" + url + "&limit=" + numComents + "&filter=stream"); HttpURLConnection cn = (HttpURLConnection) ur.openConnection(); cn.setRequestProperty("user-agent", props.getProperty("navegador")); cn.setInstanceFollowRedirects(false); cn.setUseCaches(false); cn.connect(); BufferedReader br = new BufferedReader(new InputStreamReader(cn.getInputStream())); String dirTempHtml = props.getProperty("archive_json") + "/"; File fld = new File(dirTempHtml); boolean creado = fld.exists() ? true : fld.mkdir(); if (creado) { String archFile = "archivo.json"; String archivo = dirTempHtml + archFile; String linea = null; f = new File(archivo); BufferedWriter bw = new BufferedWriter(new FileWriter(f)); while ((linea = br.readLine()) != null) { bw.append(linea); } bw.close(); cn.disconnect(); List<Fbcoment> lfb = Convertidor.getFbcomentObjects(1l, archivo); // Fbcoment.actComents(idContenido, lfb); } else { cn.disconnect(); } } catch (IOException e) { throw new JMCException(e); } }
From source file:org.jboss.aerogear.android.cookbook.agreddit.authentication.RedditAuthenticationModule.java
public void login(final String username, final String password, final Callback<HeaderAndBody> callback) { COOKIE_MANAGER = new CookieManager(null, CookiePolicy.ACCEPT_NONE); CookieHandler.setDefault(COOKIE_MANAGER); AsyncTask<Void, Void, HeaderAndBody> task = new AsyncTask<Void, Void, HeaderAndBody>() { private Exception exception; @Override// ww w . j a v a2s .co m protected HeaderAndBody doInBackground(Void... params) { HeaderAndBody result; try { HttpProvider provider = new HttpRestProvider(getLoginURL(username)); provider.setDefaultHeader("User-Agent", "AeroGear StoryList Demo /u/secondsun"); provider.setDefaultHeader("Content-Type", "application/x-www-form-urlencoded"); String loginData = buildLoginData(username, password); result = provider.post(loginData); Log.d("Auth", new String(result.getBody())); String json = new String(result.getBody()); JsonObject obj = new JsonParser().parse(json).getAsJsonObject().get("json").getAsJsonObject(); modHash = obj.get("data").getAsJsonObject().get("modhash").getAsString(); authToken = obj.get("data").getAsJsonObject().get("cookie").getAsString(); isLoggedIn = true; } catch (Exception e) { Log.e(RedditAuthenticationModule.class.getSimpleName(), "Error with Login", e); exception = e; return null; } return result; } @Override protected void onPostExecute(HeaderAndBody headerAndBody) { if (exception == null) { callback.onSuccess(headerAndBody); } else { callback.onFailure(exception); } } }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }