本文整理汇总了Java中java.net.CookieManager.setCookiePolicy方法的典型用法代码示例。如果您正苦于以下问题:Java CookieManager.setCookiePolicy方法的具体用法?Java CookieManager.setCookiePolicy怎么用?Java CookieManager.setCookiePolicy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.CookieManager
的用法示例。
在下文中一共展示了CookieManager.setCookiePolicy方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: _getClient
import java.net.CookieManager; //导入方法依赖的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;
}
示例2: post
import java.net.CookieManager; //导入方法依赖的package包/类
Call post(Callback callback) throws IOException {
OkHttpClient client = getUnsafeOkHttpClient();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
client.setCookieHandler(cookieManager);
RequestBody requestBody = new FormEncodingBuilder()
.add("user_id", NetId)
.add("user_password", password)
.build();
Request request = new Request.Builder()
.url("https://studentmaintenance.webapps.snu.edu.in/students/public/studentslist/studentslist/loginauth")
.post(requestBody)
.build();
Call call = client.newCall(request);
call.enqueue(callback);
return call;
}
示例3: tstGetPost
import java.net.CookieManager; //导入方法依赖的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);
}
示例4: setup
import java.net.CookieManager; //导入方法依赖的package包/类
private static void setup() {
baseUrlManager = new BaseUrlManager(UrlConstants.SKS1_BASE);
okHttpClient = new OkHttpClient();
cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
okHttpClient.setCookieHandler(cookieManager);
okHttpClient.setConnectTimeout(5, TimeUnit.SECONDS);
okHttpClient.setReadTimeout(5, TimeUnit.SECONDS);
okHttpClient.setWriteTimeout(5, TimeUnit.SECONDS);
okHttpClient.interceptors().add(new HandlerResponseInterceptor());
retrofit = new Retrofit.Builder()
.baseUrl(baseUrlManager)
.client(okHttpClient)
.addConverterFactory(new DocumentConverterFactory())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
service = retrofit.create(ConnectionService.class);
}
示例5: apiInit
import java.net.CookieManager; //导入方法依赖的package包/类
public static void apiInit() {
try {
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
OkHttpClient okHttpClient = new OkHttpClient.Builder()
.cookieJar(new JavaNetCookieJar(cookieManager))
.build();
retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.client(okHttpClient)
.addConverterFactory(GsonConverterFactory.create())
.build();
// Service setup
apiService = retrofit.create(CodenvyApiService.class);
} catch (Exception e) {
e.printStackTrace();
}
}
示例6: provideHttpClient
import java.net.CookieManager; //导入方法依赖的package包/类
OkHttpClient provideHttpClient() {
OkHttpClient.Builder builder = new OkHttpClient().newBuilder()
.connectTimeout(30, TimeUnit.SECONDS);
builder.addInterceptor(new KinopoiskRequestInterceptor());
// Log http requests on debug
if (BuildConfig.DEBUG) {
//logging interceptor should be last interceptor in chain
HttpLoggingInterceptor loggingInterceptor = new HttpLoggingInterceptor();
loggingInterceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
builder.addInterceptor(loggingInterceptor);
}
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
builder.cookieJar(new JavaNetCookieJar(cookieManager));
return builder.build();
}
示例7: OkNet
import java.net.CookieManager; //导入方法依赖的package包/类
private OkNet() {
OkHttpClient.Builder builder = client.newBuilder();
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_NONE);
builder.cookieJar(new JavaNetCookieJar(cookieManager));
builder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
});
builder.connectTimeout(10, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS)
.writeTimeout(20, TimeUnit.SECONDS);
client = builder.build();
}
示例8: Builder
import java.net.CookieManager; //导入方法依赖的package包/类
/**
* Creates an instance of the builder with a base URL and 2 custom builders.
*
* @param httpClientBuilder the builder to build an {@link OkHttpClient}.
* @param retrofitBuilder the builder to build a {@link Retrofit}.
*/
public Builder(OkHttpClient.Builder httpClientBuilder, Retrofit.Builder retrofitBuilder) {
if (httpClientBuilder == null) {
throw new IllegalArgumentException("httpClientBuilder == null");
}
if (retrofitBuilder == null) {
throw new IllegalArgumentException("retrofitBuilder == null");
}
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
customHeadersInterceptor = new CustomHeadersInterceptor();
// Set up OkHttp client
this.httpClientBuilder = httpClientBuilder
.cookieJar(new JavaNetCookieJar(cookieManager))
.readTimeout(60, TimeUnit.SECONDS)
.addInterceptor(new RequestIdHeaderInterceptor())
.addInterceptor(new BaseUrlHandler());
this.retrofitBuilder = retrofitBuilder;
this.loggingInterceptor = new LoggingInterceptor(LogLevel.NONE);
}
示例9: initCookieManager
import java.net.CookieManager; //导入方法依赖的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();
// }
}
示例10: buildOkHttpClient
import java.net.CookieManager; //导入方法依赖的package包/类
static OkHttpClient buildOkHttpClient() {
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
return new OkHttpClient.Builder()
.addInterceptor(new HasuraTokenInterceptor())
.addInterceptor(logging)
.cookieJar(new JavaNetCookieJar(cookieManager))
.build();
}
示例11: AuthService
import java.net.CookieManager; //导入方法依赖的package包/类
public AuthService(String authUrl) {
this.authUrl = authUrl;
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
this.httpClient
= new OkHttpClient.Builder()
.cookieJar(new JavaNetCookieJar(cookieManager))
.build();
}
示例12: startCookieSession
import java.net.CookieManager; //导入方法依赖的package包/类
private static void startCookieSession(){
cookieManager=new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
cookieManager.getCookieStore().removeAll();
if(android) {
CookieHandler.setDefault(cookieManager);
}
}
示例13: setCookieHandler
import java.net.CookieManager; //导入方法依赖的package包/类
private static void setCookieHandler()
{
synchronized (LOCK)
{
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
mOkHttpClient.setCookieHandler(cookieManager);
}
}
示例14: createOkhttp
import java.net.CookieManager; //导入方法依赖的package包/类
@NonNull
public OkHttpClient createOkhttp() {
if (null == okHttpClient) {
File httpCacheDirectory = new File(getCacheDir(getContext()), "SmartHome_Cache");
CookieManager cookieManager = new CookieManager();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieHandler.setDefault(cookieManager);
okHttpClient = new OkHttpClient.Builder().build();
}
return okHttpClient;
}
示例15: initInMemoryCookieStore
import java.net.CookieManager; //导入方法依赖的package包/类
public static CookieStore initInMemoryCookieStore() {
CookieStore cookieStore = CookieStoreHolder.getCookieStore();
if (cookieStore == null) {
CookieManager cm = new CookieManager();
cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
CookieStoreHolder.setCookieStore(cm.getCookieStore());
} else {
cookieStore.removeAll();
}
return cookieStore;
}