当前位置: 首页>>代码示例>>Java>>正文


Java CookiePolicy类代码示例

本文整理汇总了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;
    }
 
开发者ID:gzxishan,项目名称:OftenPorter,代码行数:17,代码来源:HttpUtil.java

示例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()));
	}
}
 
开发者ID:joakimkistowski,项目名称:HTTP-Load-Generator,代码行数:31,代码来源:HTTPInputGenerator.java

示例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.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:29,代码来源:CookieHttpsClientTest.java

示例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.");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:23,代码来源:CookieHttpClientTest.java

示例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;
}
 
开发者ID:anuragsai97,项目名称:Library-Token-Automation,代码行数:18,代码来源:LoginActivity.java

示例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);
}
 
开发者ID:demidenko05,项目名称:beige-software,代码行数:24,代码来源:HttpURLConnectionTest.java

示例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;
            }
        });
    }


}
 
开发者ID:dscn,项目名称:ktball,代码行数:23,代码来源:OkHttpClientManager.java

示例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;
            }
        });
    }


}
 
开发者ID:iQuick,项目名称:NewsMe,代码行数:23,代码来源:OkHttpUtils.java

示例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);
}
 
开发者ID:y3seker,项目名称:EgeYemekhaneMobil,代码行数:19,代码来源:RetrofitManager.java

示例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();
    }
}
 
开发者ID:PathriK,项目名称:CodenvyDownload-DEPRECATED,代码行数:21,代码来源:CodenvyClient.java

示例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);
}
 
开发者ID:aluxian,项目名称:Codementor,代码行数:22,代码来源:CoreServices.java

示例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();
}
 
开发者ID:x1unix,项目名称:Avi,代码行数:23,代码来源:NetworkApiFactory.java

示例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();
}
 
开发者ID:Jhanay,项目名称:OkNet,代码行数:20,代码来源:OkNet.java

示例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);
}
 
开发者ID:Azure,项目名称:autorest-clientruntime-for-java,代码行数:26,代码来源:RestClient.java

示例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();
    }

}
 
开发者ID:zhangdatao,项目名称:Emojier-Andriod,代码行数:20,代码来源:HttpManager.java


注:本文中的java.net.CookiePolicy类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。