本文整理汇总了Java中org.apache.http.impl.cookie.BasicClientCookie.setDomain方法的典型用法代码示例。如果您正苦于以下问题:Java BasicClientCookie.setDomain方法的具体用法?Java BasicClientCookie.setDomain怎么用?Java BasicClientCookie.setDomain使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.impl.cookie.BasicClientCookie
的用法示例。
在下文中一共展示了BasicClientCookie.setDomain方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: buildCookie
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
@Override
protected void buildCookie(com.intuit.karate.http.Cookie c) {
BasicClientCookie cookie = new BasicClientCookie(c.getName(), c.getValue());
for (Entry<String, String> entry : c.entrySet()) {
switch (entry.getKey()) {
case DOMAIN:
cookie.setDomain(entry.getValue());
break;
case PATH:
cookie.setPath(entry.getValue());
break;
}
}
if (cookie.getDomain() == null) {
cookie.setDomain(uriBuilder.getHost());
}
cookieStore.addCookie(cookie);
}
示例2: getuCookie
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
public static CookieStore getuCookie() {
CookieStore uCookie = new BasicCookieStore();
try {
String COOKIE_S_LINKDATA = LemallPlatform.getInstance().getCookieLinkdata();
if (!TextUtils.isEmpty(COOKIE_S_LINKDATA)) {
String[] cookies = COOKIE_S_LINKDATA.split("&");
for (String item : cookies) {
String[] keyValue = item.split(SearchCriteria.EQ);
if (keyValue.length == 2) {
if (OtherUtil.isContainsChinese(keyValue[1])) {
keyValue[1] = URLEncoder.encode(keyValue[1], "UTF-8");
}
BasicClientCookie cookie = new BasicClientCookie(keyValue[0], keyValue[1]);
cookie.setVersion(0);
cookie.setDomain(".lemall.com");
cookie.setPath("/");
uCookie.addCookie(cookie);
}
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return uCookie;
}
示例3: saveCookie
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
private static void saveCookie(String url){
String cookie = CookieManager.getInstance().getCookie(url);
if(cookie !=null && !cookie.equals("")){
String[] cookies = cookie.split(";");
for(int i=0; i< cookies.length; i++){
String[] nvp = cookies[i].split("=");
BasicClientCookie c = new BasicClientCookie(nvp[0], nvp[1]);
//c.setVersion(0);
c.setDomain("kyfw.12306.cn");
MyCookieStore myCookieStore = null;
if (MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore()
instanceof MyCookieStore){
myCookieStore = (MyCookieStore)MyApp.getInstance().getCommonBInfo().getHttpHelper().getHttpClient().getCookieStore();
}
if (myCookieStore != null){
myCookieStore.addCookie(c);
}
}
}
CookieSyncManager.getInstance().sync();
}
示例4: saveCookies
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
public void saveCookies() throws IOException {
CookieManager cm = getWebClient().getCookieManager();
ArrayList<BasicClientCookie> list = new ArrayList<>();
for (Cookie c : cm.getCookies()) {
BasicClientCookie bc = new BasicClientCookie(c.getName(), c.getValue());
bc.setDomain(c.getDomain());
bc.setPath(c.getPath());
list.add(bc);
}
File cookiesFile = Directories.META.getDir("cookies.json");
if (cookiesFile.exists()) {
cookiesFile.delete();
}
String o = new Gson().toJson(list);
FileUtils.writeByteArrayToFile(cookiesFile, o.getBytes());
}
示例5: batchCookie
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
/**
* batchCookies
*
* @param cookiestring
* the cookie string, eg.:"a=b;c=a"
* @param domain
* the domain
* @param path
* the path
* @param expired
* the expired date
*/
public synchronized void batchCookie(String cookiestring, String domain, String path, Date expired) {
String[] ss = X.split(cookiestring, ";");
for (String s : ss) {
StringFinder sf = StringFinder.create(s);
String name = sf.nextTo("=");
String value = sf.remain();
if (!X.isEmpty(name)) {
removeCookie(name, domain, path);
BasicClientCookie c = new BasicClientCookie(name, value);
c.setDomain(domain);
c.setPath(X.isEmpty(path) ? "/" : path);
c.setExpiryDate(expired);
cookies.addCookie(c);
}
}
}
示例6: createApacheCookieStore
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
public static ConcurrentCookieJar createApacheCookieStore(HttpDownloaderConfig config) {
List<HttpDownloaderConfig.Cookie> cookies = config.getCookies();
if (cookies == null) {
return null;
}
ConcurrentCookieJar store = new ConcurrentCookieJar();
for (HttpDownloaderConfig.Cookie cookie : cookies) {
String[] values = cookie.cookie.split("; ");
for (int i = 0; i < values.length; i++) {
String[] kv = values[i].split("=", 2);
BasicClientCookie cc = new BasicClientCookie(kv[0], kv[1]);
cc.setPath(cookie.path);
cc.setDomain(cookie.domain);
store.addCookie(cc);
}
}
return store;
}
示例7: storeCookie
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
private String storeCookie(CloseableHttpResponse response) {
Header cookieHeader = response.getFirstHeader("set-cookie");
if (cookieHeader != null) {
mTokenHeader = cookieHeader.getValue();
String token = mTokenHeader.substring(8, mTokenHeader.indexOf(';'));
mCookieStore.clear();
BasicClientCookie cookie = new BasicClientCookie(BBOX_COOKIE_NAME, token);
cookie.setDomain(BBOX_HOST);
mCookieStore.addCookie(cookie);
return token;
}
return null;
}
示例8: clearCookieForHost
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
protected synchronized void clearCookieForHost(String sessionHost) throws Exception {
Cookie sessionCookie = null;
for (Cookie cookie : cookieStore.getCookies()) {
String cookieDomain = cookie.getDomain();
if (cookieDomain != null) {
if (sessionHost.equals(cookieDomain) ||
sessionHost.indexOf(cookieDomain) != -1 ||
cookieDomain.indexOf(sessionHost) != -1) {
sessionCookie = cookie;
break;
}
}
}
if (sessionCookie != null) {
BasicClientCookie httpCookie = new BasicClientCookie(sessionCookie.getName(), sessionCookie.getValue());
httpCookie.setExpiryDate(new Date(0));
httpCookie.setVersion(1);
httpCookie.setPath(sessionCookie.getPath());
httpCookie.setDomain(sessionCookie.getDomain());
cookieStore.addCookie(httpCookie);
}
cookieStore.clearExpired(new Date()); // this should clear the cookie
}
示例9: getAccessToken
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
public static String getAccessToken(String sessionId, String csrfToken)
throws Exception {
DefaultHttpClient client = new DefaultHttpClient();
client.getParams().setBooleanParameter(
"http.protocol.handle-redirects", false);
CookieStore cookies = new BasicCookieStore();
BasicClientCookie csrfCookie = new BasicClientCookie(
"csrftoken", csrfToken);
csrfCookie.setDomain(Urls.OAUTH_HOSTNAME);
csrfCookie.setPath("/");
cookies.addCookie(csrfCookie);
BasicClientCookie sessionCookie = new BasicClientCookie(
"sessionid", sessionId);
sessionCookie.setDomain(Urls.OAUTH_HOSTNAME);
sessionCookie.setPath("/");
cookies.addCookie(sessionCookie);
client.setCookieStore(cookies);
authorizeClient(client);
return getAccessToken(client,
getAuthorizationCode(client,
authorizeClient(client, csrfToken)));
}
示例10: convertCookie
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
/**
* Converts Selenium cookie to Apache http client.
* @param browserCookie selenium cookie.
* @return http client format.
*/
protected ClientCookie convertCookie(Cookie browserCookie) {
BasicClientCookie cookie = new BasicClientCookie(browserCookie.getName(), browserCookie.getValue());
String domain = browserCookie.getDomain();
if (domain != null && domain.startsWith(".")) {
// http client does not like domains starting with '.', it always removes it when it receives them
domain = domain.substring(1);
}
cookie.setDomain(domain);
cookie.setPath(browserCookie.getPath());
cookie.setExpiryDate(browserCookie.getExpiry());
cookie.setSecure(browserCookie.isSecure());
if (browserCookie.isHttpOnly()) {
cookie.setAttribute("httponly", "");
}
return cookie;
}
示例11: initRequest
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
@Override
protected void initRequest(HttpUriRequest request)
{
super.initRequest(request);
// Set the timezone cookie
TimeZone tz = TimeZone.getDefault();
int utcOffsetMinutes = tz.getOffset(System.currentTimeMillis())/(1000*60);
BasicClientCookie cookie = new BasicClientCookie("UtcOffsetMinutes",
String.valueOf(utcOffsetMinutes));
cookie.setPath("/");
cookie.setDomain(".xbox.com");
mHttpClient.getCookieStore().addCookie(cookie);
}
示例12: activateBrowserfeatures
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
@Override
public void activateBrowserfeatures(final Upload upload) throws UnirestException {
// Create a local instance of cookie store
// Populate cookies if needed
final CookieStore cookieStore = new BasicCookieStore();
for (final PersistentCookieStore.SerializableCookie serializableCookie : upload.getAccount().getSerializeableCookies()) {
final BasicClientCookie cookie = new BasicClientCookie(serializableCookie.getCookie().getName(), serializableCookie.getCookie().getValue());
cookie.setDomain(serializableCookie.getCookie().getDomain());
cookieStore.addCookie(cookie);
}
final HttpClient client = HttpClientBuilder.create().useSystemProperties().setDefaultCookieStore(cookieStore).build();
Unirest.setHttpClient(client);
final HttpResponse<String> response = Unirest.get(String.format(VIDEO_EDIT_URL, upload.getVideoid())).asString();
changeMetadata(response.getBody(), upload);
final RequestConfig clientConfig = RequestConfig.custom().setConnectTimeout(600000).setSocketTimeout(600000).build();
Unirest.setHttpClient(HttpClientBuilder.create().setDefaultRequestConfig(clientConfig).build());
}
示例13: importCookies
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
public static void importCookies(CookieStore cookieStore, JSONArray cookies) {
cookieStore.clear();
for (int i = 0; i < cookies.length(); i++) {
try {
JSONObject json = cookies.getJSONObject(i);
if (json.has("domain") && json.has("expiryDate")
&& json.has("name") && json.has("value")) {
BasicClientCookie cookie = new BasicClientCookie(json.getString("name"), json.getString("value"));
cookie.setDomain(json.getString("domain"));
cookie.setPath(json.getString("path"));
long expiryTs = json.getLong("expiryDate");
cookie.setExpiryDate(new Date(expiryTs));
cookieStore.addCookie(cookie);
}
} catch (JSONException e) {
logger.error(e.getMessage(), e);
}
}
}
示例14: getAllCookies
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
public List<Cookie> getAllCookies() {
List<Cookie> cookies = new ArrayList<Cookie>();
Cursor cursor = db
.query(TABLE_NAME, null, null, null, null, null, null);
for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
String name = cursor.getString(cursor.getColumnIndex(Column.NAME));
String value = cursor
.getString(cursor.getColumnIndex(Column.VALUE));
BasicClientCookie cookie = new BasicClientCookie(name, value);
cookie.setComment(cursor.getString(cursor
.getColumnIndex(Column.COMMENT)));
cookie.setDomain(cursor.getString(cursor
.getColumnIndex(Column.DOMAIN)));
long expireTime = cursor.getLong(cursor
.getColumnIndex(Column.EXPIRY_DATE));
if (expireTime != 0) {
cookie.setExpiryDate(new Date(expireTime));
}
cookie.setPath(cursor.getString(cursor.getColumnIndex(Column.PATH)));
cookie.setSecure(cursor.getInt(cursor.getColumnIndex(Column.SECURE)) == 1);
cookie.setVersion(cursor.getInt(cursor
.getColumnIndex(Column.VERSION)));
cookies.add(cookie);
}
cursor.close();
return cookies;
}
示例15: readObject
import org.apache.http.impl.cookie.BasicClientCookie; //导入方法依赖的package包/类
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
String name = (String) in.readObject();
String value = (String) in.readObject();
clientCookie = new BasicClientCookie(name, value);
clientCookie.setComment((String) in.readObject());
clientCookie.setDomain((String) in.readObject());
clientCookie.setExpiryDate((Date) in.readObject());
clientCookie.setPath((String) in.readObject());
clientCookie.setVersion(in.readInt());
clientCookie.setSecure(in.readBoolean());
}