本文整理汇总了Java中java.net.CookieHandler类的典型用法代码示例。如果您正苦于以下问题:Java CookieHandler类的具体用法?Java CookieHandler怎么用?Java CookieHandler使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
CookieHandler类属于java.net包,在下文中一共展示了CookieHandler类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: copyWithDefaults
import java.net.CookieHandler; //导入依赖的package包/类
OkHttpClient copyWithDefaults() {
OkHttpClient result = new OkHttpClient(this);
if (result.proxySelector == null) {
result.proxySelector = ProxySelector.getDefault();
}
if (result.cookieHandler == null) {
result.cookieHandler = CookieHandler.getDefault();
}
if (result.socketFactory == null) {
result.socketFactory = SocketFactory.getDefault();
}
if (result.sslSocketFactory == null) {
result.sslSocketFactory = getDefaultSSLSocketFactory();
}
if (result.hostnameVerifier == null) {
result.hostnameVerifier = OkHostnameVerifier.INSTANCE;
}
if (result.certificatePinner == null) {
result.certificatePinner = CertificatePinner.DEFAULT;
}
if (result.authenticator == null) {
result.authenticator = AuthenticatorAdapter.INSTANCE;
}
if (result.connectionPool == null) {
result.connectionPool = ConnectionPool.getDefault();
}
if (result.protocols == null) {
result.protocols = DEFAULT_PROTOCOLS;
}
if (result.connectionSpecs == null) {
result.connectionSpecs = DEFAULT_CONNECTION_SPECS;
}
if (result.dns == null) {
result.dns = Dns.SYSTEM;
}
return result;
}
示例2: copyWithDefaults
import java.net.CookieHandler; //导入依赖的package包/类
/**
* Returns a shallow copy of this OkHttpClient that uses the system-wide default for
* each field that hasn't been explicitly configured.
*/
private OkHttpClient copyWithDefaults() {
OkHttpClient result = new OkHttpClient(this);
result.proxy = proxy;
result.proxySelector = proxySelector != null ? proxySelector : ProxySelector.getDefault();
result.cookieHandler = cookieHandler != null ? cookieHandler : CookieHandler.getDefault();
result.responseCache = responseCache != null ? responseCache : ResponseCache.getDefault();
result.sslSocketFactory = sslSocketFactory != null
? sslSocketFactory
: HttpsURLConnection.getDefaultSSLSocketFactory();
result.hostnameVerifier = hostnameVerifier != null
? hostnameVerifier
: OkHostnameVerifier.INSTANCE;
result.authenticator = authenticator != null
? authenticator
: HttpAuthenticator.SYSTEM_DEFAULT;
result.connectionPool = connectionPool != null ? connectionPool : ConnectionPool.getDefault();
result.followProtocolRedirects = followProtocolRedirects;
result.transports = transports != null ? transports : DEFAULT_TRANSPORTS;
result.connectTimeout = connectTimeout;
result.readTimeout = readTimeout;
return result;
}
示例3: createViews
import java.net.CookieHandler; //导入依赖的package包/类
private void createViews() {
mediaDataSourceFactory = buildDataSourceFactory(true);
mainHandler = new Handler();
window = new Timeline.Window();
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
}
LayoutParams layoutParams = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT);
exoPlayerView = new ExoPlayerView(getContext());
exoPlayerView.setLayoutParams(layoutParams);
addView(exoPlayerView, 0, layoutParams);
}
示例4: _getClient
import java.net.CookieHandler; //导入依赖的package包/类
private static OkHttpClientImpl _getClient(CookieHandler cookieHandler) {
OkHttpClientImpl okHttpClient = new OkHttpClientImpl();
//okHttpClient.setConnectTimeout(SET_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS);
//okHttpClient.setReadTimeout(SET_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
//okHttpClient.setWriteTimeout(SET_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS);
if (cookieHandler == null) {
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
okHttpClient._setCookieHandler(cookieManager);
} else {
okHttpClient._setCookieHandler(cookieHandler);
}
return okHttpClient;
}
示例5: onCreate
import java.net.CookieHandler; //导入依赖的package包/类
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
shouldAutoPlay = true;
clearResumePosition();
mediaDataSourceFactory = buildDataSourceFactory(true);
mainHandler = new Handler();
if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) {
CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER);
}
setContentView(R.layout.player_activity);
View rootView = findViewById(R.id.root);
rootView.setOnClickListener(this);
debugRootView = (LinearLayout) findViewById(R.id.controls_root);
debugTextView = (TextView) findViewById(R.id.debug_text_view);
retryButton = (Button) findViewById(R.id.retry_button);
retryButton.setOnClickListener(this);
simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view);
simpleExoPlayerView.setControllerVisibilityListener(this);
simpleExoPlayerView.requestFocus();
}
示例6: SoapSession
import java.net.CookieHandler; //导入依赖的package包/类
public SoapSession(URL institutionUrl, String username, String password) throws Exception
{
this.institutionUrl = institutionUrl;
encoder = new Base64(-1);
CookieHandler.setDefault(new BasicCookieHandler());
final URL endpointUrl = new URL(institutionUrl, "services/SoapService51");
System.setProperty("axis.socketFactory", "com.dytech.edge.importexport.TleDefaultSocketFactory");
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SLF4JLog");
System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.SLF4JLogFactory");
final CustomSoapService51Locator locator = new CustomSoapService51Locator();
client = locator.getSoapService51Endpoint(endpointUrl);
final PropBagEx userXml = new PropBagEx(client.login(username, password));
userId = userXml.getNode("uuid");
loggedIn = true;
final Map<String, List<String>> fakeHeaders = new HashMap<String, List<String>>();
fakeHeaders.put("Set-Cookie", locator.getCookiesForUrl(endpointUrl));
CookieHandler.getDefault().put(endpointUrl.toURI(), fakeHeaders);
new KeepAlive().start();
}
示例7: networkRequest
import java.net.CookieHandler; //导入依赖的package包/类
private Request networkRequest(Request request) throws IOException {
Request.Builder result = request.newBuilder();
if (request.header("Host") == null) {
result.header("Host", Util.hostHeader(request.httpUrl()));
}
if (request.header("Connection") == null) {
result.header("Connection", "Keep-Alive");
}
if (request.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING) == null) {
this.transparentGzip = true;
result.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING, AsyncHttpClient.ENCODING_GZIP);
}
CookieHandler cookieHandler = this.client.getCookieHandler();
if (cookieHandler != null) {
OkHeaders.addCookies(result, cookieHandler.get(request.uri(), OkHeaders.toMultimap
(result.build().headers(), null)));
}
if (request.header(Network.USER_AGENT) == null) {
result.header(Network.USER_AGENT, Version.userAgent());
}
return result.build();
}
示例8: doClientSide
import java.net.CookieHandler; //导入依赖的package包/类
void doClientSide() throws Exception {
// Wait for server to get started.
while (!serverReady) {
Thread.sleep(50);
}
HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() {
public boolean verify(String hostname, SSLSession session) {
return true;
}});
URL url = new URL("https://localhost:" + serverPort +"/");
// Run without a CookieHandler first
InputStream in = url.openConnection().getInputStream();
while (in.read() != -1); // read response body so connection can be reused
// Set a CookeHandler and retest using the HttpClient from the KAC
CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
in = url.openConnection().getInputStream();
while (in.read() != -1);
if (manager.getCookieStore().getCookies().isEmpty()) {
throw new RuntimeException("Failed: No cookies in the cookie Handler.");
}
}
示例9: CookieHttpClientTest
import java.net.CookieHandler; //导入依赖的package包/类
CookieHttpClientTest() throws Exception {
/* start the server */
ss = new ServerSocket(0);
(new Thread(this)).start();
URL url = new URL("http://localhost:" + ss.getLocalPort() +"/");
// Run without a CookieHandler first
InputStream in = url.openConnection().getInputStream();
while (in.read() != -1); // read response body so connection can be reused
// Set a CookeHandler and retest using the HttpClient from the KAC
CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(manager);
in = url.openConnection().getInputStream();
while (in.read() != -1);
if (manager.getCookieStore().getCookies().isEmpty()) {
throw new RuntimeException("Failed: No cookies in the cookie Handler.");
}
}
示例10: initCookies
import java.net.CookieHandler; //导入依赖的package包/类
private void initCookies() {
CookieManager cookieManager = new CookieManager();
CookieHandler.setDefault(cookieManager);
if (cookieManager.getCookieStore().getCookies().size() == 0) {
try {
String url = SharedPreferencesEditor.getInstance().getString(
Constants.PREFS_URL_SHORTCUT);
URI uri = new URI(url);
HttpCookie cookie = new HttpCookie(Constants.COOKIE_AUTH_NAME,
SharedPreferencesEditor.getInstance().getString(
Constants.PREFS_AUTH));
cookie.setDomain(uri.getHost());
cookie.setPath(Constants.COOKIE_BASE_PATH);
cookie.setVersion(0);
cookie.setMaxAge((new Date()).getTime()
+ Constants.COOKIE_LIFETIME_YEAR);
cookieManager.getCookieStore().add(uri, cookie);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}
示例11: tstGetPost
import java.net.CookieHandler; //导入依赖的package包/类
public void tstGetPost() throws Exception {
String urlSource = "http://localhost:8080/beige-accounting-web/secure/main.jsp";
String urlBase = urlSource.substring(0, urlSource.indexOf("secure") - 1);
assertEquals("http://localhost:8080/beige-accounting-web", urlBase);
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
URL url = new URL(urlSource);
Map<String, Object> params = new HashMap<String, Object>();
params.put("userName", "admin");
params.put("userPass", "admin");
params.put("authMethod", "form");
params.put("urlBase", urlBase);
params.put("authUrl", urlBase + "/secure/j_security_check");
params.put("authUserName", "j_username");
params.put("authUserPass", "j_password");
params.put("urlSource", urlSource);
tstAuthGet(url, params, cookieManager); //either Get or Post for test allowed
urlSource = "http://localhost:8080/beige-accounting-web/secure/sendEntities";
params.put("urlSource", urlSource);
//url = new URL(urlSource);
//tstAuthPost(url, params, cookieManager);
}
示例12: processCookie
import java.net.CookieHandler; //导入依赖的package包/类
void processCookie(String url, Map<String, List<String>> headers) {
if (!isUseCookie()) {
return;
}
try {
CookieHandler cookieManager = getCookieHandler();
Map<String, List<String>> singleMap =
cookieManager.get(URI.create(url), new HashMap<String, List<String>>(0));
List<String> cookies = singleMap.get("Cookie");
if (cookies != null) {
headers.put("Cookie", Collections.singletonList(TextUtils.join(";", cookies)));
}
} catch (Throwable ex) {
LogUtil.e(ex.getMessage(), ex);
}
}
示例13: onCreate
import java.net.CookieHandler; //导入依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
android.webkit.CookieManager.getInstance().setAcceptCookie(true);
CookieManager cookieManager = new CookieManager(new PersistentCookieStore(getApplicationContext()), CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
new APITask(new APICallback() {
@Override
public void r(String result) {
if (result.length() != 0) {
Intent queueList = new Intent(MainActivity.this, QueueListActivity.class);
startActivity(queueList);
} else {
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
}
}
}).execute("method", "userData");
}
示例14: main
import java.net.CookieHandler; //导入依赖的package包/类
public static void main(String[] args) {
AppVars.setAppVars();
Preferences.load();
if (Preferences.useSystemLookAndFeel()) {
useSystemLookAndFeel(true);
}
CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
if (Preferences.useUserProxy()) {
ComicUtil.setProxy(Preferences.getProxyAddress(), Preferences.getProxyPort(), Preferences.getProxyUsername(), Preferences.getProxyEncryptedPassword());
}
ComicUtil.getNewestComic();
EventQueue.invokeLater(() -> {
MainFrame frame = new MainFrame("XKCDownload");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
frame.setLocationRelativeTo(null);
});
}
示例15: initCookieManager
import java.net.CookieHandler; //导入依赖的package包/类
public static void initCookieManager() {
CookieHandler cookieHandler = CookieHandler.getDefault();
if (cookieHandler == null) {
// CookieStore cookieStore = CookieStoreHolder.initInMemoryCookieStore();
// CookieManager cm = new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL);
CookieManager cm = new CookieManager();
cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cm);
}
// else {
// CookieStoreHolder.initInMemoryCookieStore();
// }
}