本文整理匯總了Java中java.net.CookiePolicy類的典型用法代碼示例。如果您正苦於以下問題:Java CookiePolicy類的具體用法?Java CookiePolicy怎麽用?Java CookiePolicy使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
CookiePolicy類屬於java.net包,在下文中一共展示了CookiePolicy類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: _getClient
import java.net.CookiePolicy; //導入依賴的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: HTTPInputGenerator
import java.net.CookiePolicy; //導入依賴的package包/類
/**
* Constructs a new HTTPInputGenerator using a Lua generation script.
* The Lua script must contain the onInit() and onCall(callnum) functions.
* onCall(callnum) must return the HTTP request for a specific call with number callnum.
* callnum begins at 1 (Lua convention) and increments for each call. It resets back to 1
* if onCall returns nil.
* @param scriptFile The url generator script.
* @param randomSeed Seed for Lua random function.
* @param timeout The http read timeout.
*/
public HTTPInputGenerator(File scriptFile, int randomSeed, int timeout) {
OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL);
httpClientBuilder = httpClientBuilder.cookieJar(new JavaNetCookieJar(cookieManager));
if (timeout > 0) {
httpClientBuilder = httpClientBuilder.readTimeout(timeout, TimeUnit.MILLISECONDS)
.connectTimeout(timeout, TimeUnit.MILLISECONDS);
}
httpClient = httpClientBuilder.build();
if (scriptFile != null) {
luaGlobals = JsePlatform.standardGlobals();
//luaGlobals.get("require").call(LuaValue.valueOf("tools.descartes.httploadgenerator.http.lua.HTML"));
LuaValue library = new LuaTable();
library.set("getMatches", new GetMatches(htmlFunctions));
library.set("extractMatches", new ExtractAllMatches(htmlFunctions));
luaGlobals.set("html", library);
luaGlobals.get("math").get("randomseed").call(LuaValue.valueOf(5));
luaGlobals.get("dofile").call(LuaValue.valueOf(scriptFile.getAbsolutePath()));
}
}
示例3: doClientSide
import java.net.CookiePolicy; //導入依賴的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.");
}
}
示例4: CookieHttpClientTest
import java.net.CookiePolicy; //導入依賴的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.");
}
}
示例5: post
import java.net.CookiePolicy; //導入依賴的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;
}
示例6: tstGetPost
import java.net.CookiePolicy; //導入依賴的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);
}
示例7: OkHttpClientManager
import java.net.CookiePolicy; //導入依賴的package包/類
private OkHttpClientManager()
{
mOkHttpClient = new OkHttpClient();
//cookie enabled
mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
mDelivery = new Handler(Looper.getMainLooper());
mGson = new Gson();
//just for test
if (false)
{
mOkHttpClient.setHostnameVerifier(new HostnameVerifier()
{
@Override
public boolean verify(String hostname, SSLSession session)
{
return true;
}
});
}
}
示例8: OkHttpUtils
import java.net.CookiePolicy; //導入依賴的package包/類
private OkHttpUtils()
{
mOkHttpClient = new OkHttpClient();
//cookie enabled
mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
mDelivery = new Handler(Looper.getMainLooper());
if (true)
{
mOkHttpClient.setHostnameVerifier(new HostnameVerifier()
{
@Override
public boolean verify(String hostname, SSLSession session)
{
return true;
}
});
}
}
示例9: setup
import java.net.CookiePolicy; //導入依賴的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);
}
示例10: apiInit
import java.net.CookiePolicy; //導入依賴的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();
}
}
示例11: CoreServices
import java.net.CookiePolicy; //導入依賴的package包/類
public CoreServices(Context context) {
this.context = context;
// Storage
sharedPrefs = PreferenceManager.getDefaultSharedPreferences(context);
cookieStore = new PersistentCookieStore(context);
// General
userManager = new UserManager(sharedPrefs);
errorHandler = new ErrorHandler(context);
localBroadcastManager = LocalBroadcastManager.getInstance(context);
// Network
firebaseRef = new Firebase(Constants.FIREBASE_URL);
okHttpClient = new OkHttpClient();
okHttpClient.setCookieHandler(new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL));
// Tasks
codementorTasks = new CodementorTasks(okHttpClient);
firebaseTasks = new FirebaseTasks(firebaseRef, codementorTasks, userManager);
}
示例12: provideHttpClient
import java.net.CookiePolicy; //導入依賴的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();
}
示例13: OkNet
import java.net.CookiePolicy; //導入依賴的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();
}
示例14: Builder
import java.net.CookiePolicy; //導入依賴的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);
}
示例15: HttpManager
import java.net.CookiePolicy; //導入依賴的package包/類
private HttpManager() {
this.mOkHttpClient = new OkHttpClient();
//cookie enabled
mOkHttpClient.setCookieHandler(new CookieManager(null, CookiePolicy.ACCEPT_ORIGINAL_SERVER));
mDelivery = new Handler(Looper.getMainLooper());
final int sdk = Build.VERSION.SDK_INT;
if (sdk >= 23) {
GsonBuilder gsonBuilder = new GsonBuilder()
.excludeFieldsWithModifiers(
Modifier.FINAL,
Modifier.TRANSIENT,
Modifier.STATIC);
mGson = gsonBuilder.create();
} else {
mGson = new Gson();
}
}