List of usage examples for java.net CookieManager CookieManager
public CookieManager()
From source file:at.becast.youploader.youtube.data.CookieJar.java
public CookieJar() { store = new CookieManager().getCookieStore(); }
From source file:fr.outadev.skinswitch.network.MojangConnectionHandler.java
public MojangConnectionHandler(Context context) { super(context); CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); }
From source file:org.utils.HttpCapcha.java
/** * * @return /*from ww w . j av a 2 s . c o m*/ */ public MainVars Start(MainVars mainvars) { Log.d(LOG_TAG, "Destination Url," + Url); String responseBody = null; // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpGet httppost = new HttpGet(Url.toString()); CookieHandler.setDefault(new CookieManager()); try { // Add your data //List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); // nameValuePairs.add(new BasicNameValuePair("Json", this.Json)); // nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi")); // httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httppost.setHeader("Host", "78.46.251.139"); httppost.setHeader("User-Agent", USER_AGENT); httppost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httppost.setHeader("Accept-Language", "en-US,en;q=0.5"); httppost.setHeader("Cookie", getCookies()); httppost.setHeader("Connection", "keep-alive"); httppost.setHeader("Referer", "https://accounts.google.com/ServiceLoginAuth"); httppost.setHeader("Content-Type", "application/x-www-form-urlencoded"); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); // setCookies(response.getFirstHeader("Set-Cookie") == null ? "" : // response.getFirstHeader("Set-Cookie").toString()); // int responseCode = response.getStatusLine().getStatusCode(); // Log.d(LOG_TAG,"Response code,"+responseCode); // switch (responseCode) { // case 200: // HttpEntity entity = response.getEntity(); // if (entity != null) { // // responseBody = EntityUtils.toString(entity); // // InputStream instream = entity.getContent(); // //mainvars.setBitmap(BitmapFactory.decodeStream(instream)); // } // break; // } // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } // mainvars.setResponse(responseBody); return (mainvars); }
From source file:org.utils.HttpDriver.java
/** * * @param mainvars// w ww . j a v a2 s .co m * @return */ public String Start() { Log.d(LOG_TAG, "Destination Url," + Url); Log.d(LOG_TAG, "Post Send Json," + Json); String responseBody = null; // Create a new HttpClient and Post Header HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(Url.toString()); CookieHandler.setDefault(new CookieManager()); try { // Add your data List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("Json", this.Json)); // nameValuePairs.add(new BasicNameValuePair("stringdata", "Hi")); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httppost.setHeader("Host", "78.46.251.139"); httppost.setHeader("User-Agent", USER_AGENT); httppost.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); httppost.setHeader("Accept-Language", "en-US,en;q=0.5"); httppost.setHeader("Cookie", cookies + ";"); httppost.setHeader("Connection", "keep-alive"); httppost.setHeader("Referer", "https://accounts.google.com/ServiceLoginAuth"); httppost.setHeader("Content-Type", "application/x-www-form-urlencoded"); Log.d(LOG_TAG, "Post Send Cookies," + cookies + ";"); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int responseCode = response.getStatusLine().getStatusCode(); Log.d(LOG_TAG, "Response code," + responseCode); switch (responseCode) { case 200: HttpEntity entity = response.getEntity(); if (entity != null) { responseBody = EntityUtils.toString(entity); } break; } } catch (ClientProtocolException e) { // TODO Auto-generated catch block } catch (IOException e) { // TODO Auto-generated catch block } return (responseBody); }
From source file:me.senwang.newpdademo.MainActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.activity_main); String test = "111"; boolean testb = test.equals(null); mSidEdit = (EditText) findViewById(R.id.sid_edit); mUserNameEdit = (EditText) findViewById(R.id.user_name_edit); mPasswordEdit = (EditText) findViewById(R.id.password_edit); mTextView = (TextView) findViewById(R.id.text); CookieManager cm = new CookieManager(); CookieHandler.setDefault(cm); }
From source file:fi.elfcloud.sci.Connection.java
public Connection(Client client) { Connection.client = client;//from w ww .j av a 2s.c o m Connection.manager = new CookieManager(); Connection.manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(Connection.manager); Connection.cookieJar = manager.getCookieStore(); Connection.cookies = cookieJar.getCookies(); }
From source file:CookieAccessor.java
/** * Get cookies for a url from cookie store *//*from w ww. j av a 2 s. co m*/ public void getCookieUsingCookieHandler() { try { // instantiate CookieManager; make sure to set CookiePolicy CookieManager manager = new CookieManager(); manager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); // get content from URLConnection; cookies are set by web site URL url = new URL("http://host.example.com"); URLConnection connection = url.openConnection(); connection.getContent(); // get cookies from underlying CookieStore CookieStore cookieJar = manager.getCookieStore(); List<HttpCookie> cookies = cookieJar.getCookies(); for (HttpCookie cookie : cookies) { System.out.println("CookieHandler retrieved cookie: " + cookie); } } catch (Exception e) { System.out.println("Unable to get cookie using CookieHandler"); e.printStackTrace(); } }
From source file:org.exoplatform.utils.image.CookieAwarePicassoDownloader.java
/** * Creates a new CookieManager if none already exists and sets it as the * default CookieHandler//from w w w . j av a2 s . c om * * @return the CookieManager newly created, or the existing one if it's * already the default CookieHandler */ private CookieManager initCookieManager() { CookieHandler handler = CookieHandler.getDefault(); CookieManager manager; if (handler == null || !(handler instanceof CookieManager)) { manager = new CookieManager(); CookieHandler.setDefault(manager); // Sync cookies from ExoConnectionUtils only // when the Cookies Manager is created syncCookies(manager); } else { manager = (CookieManager) handler; } return manager; }
From source file:nl.phanos.liteliveresultsclient.LoginHandler.java
public LoginHandler() throws Exception { String url = "https://www.atletiek.nu/login/"; // make sure cookies is turn on CookieHandler.setDefault(new CookieManager()); String page = this.GetPageContent(url); String user = Main.getWindow().UserName; String pass = Main.getWindow().Pass; List<NameValuePair> postParams = this.getFormParams(page, user, pass); this.sendPost(url, postParams); }