本文整理匯總了Java中org.apache.http.impl.cookie.BasicClientCookie.setPath方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicClientCookie.setPath方法的具體用法?Java BasicClientCookie.setPath怎麽用?Java BasicClientCookie.setPath使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.cookie.BasicClientCookie
的用法示例。
在下文中一共展示了BasicClientCookie.setPath方法的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: 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());
}
示例4: createContext
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
@Override
public BasicHttpContext createContext(final HttpHost targetHost) {
final CookieStore cookieStore = new BasicCookieStore();
final BasicClientCookie clientCookie =
new BasicClientCookie(cookie.getName(), cookie.getValue());
clientCookie.setDomain(targetHost.getHostName());
clientCookie.setPath("/");
cookieStore.addCookie(clientCookie);
final BasicHttpContext context = new BasicHttpContext();
context.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
return context;
}
示例5: authToGoogle
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
/**
* Authentication with google account
* @param cookies cookies list keys from google auth
* @param login username associated to zds login
* @param id user id on ZdS associated to login
*/
public void authToGoogle(List<HttpCookie> cookies, String login, String id) {
if(login != null && id != null) {
this.login = login;
this.idUser = id;
log.info("L'identifiant de l'utilisateur " + this.login + " est : " + idUser);
cookieStore = new BasicCookieStore();
for(HttpCookie cookie:cookies) {
BasicClientCookie c = new BasicClientCookie(cookie.getName(), cookie.getValue());
c.setDomain(cookie.getDomain());
c.setPath(cookie.getPath());
c.setSecure(cookie.getSecure());
c.setVersion(cookie.getVersion());
c.setComment(cookie.getComment());
cookieStore.addCookie(c);
}
context.setCookieStore(cookieStore);
this.authenticated = true;
}
else {
log.debug("Le login de l'utilisateur n'a pas pu être trouvé");
}
}
示例6: 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);
}
}
}
示例7: 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
}
示例8: 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;
}
示例9: testCookiesAreCapturedWhenRequested
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
@Test
public void testCookiesAreCapturedWhenRequested() throws IOException {
proxy.setCaptureContent(true);
proxy.newHar("Test");
BasicClientCookie cookie = new BasicClientCookie("foo", "bar");
cookie.setDomain("127.0.0.1");
cookie.setPath("/");
client.getCookieStore().addCookie(cookie);
// set the cookie on the server side
String body = IOUtils.readFully(client.execute(new HttpGet(ECHO_URL)).getEntity().getContent());
System.out.println(body);
Har har = proxy.getHar();
HarEntry entry = har.getLog().getEntries().get(0);
HarCookie harCookie = entry.getRequest().getCookies().get(0);
Assert.assertEquals("foo", harCookie.getName());
Assert.assertEquals("bar", harCookie.getValue());
}
示例10: shareCookies
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
/**
* Share the cookies with HttpClientTask
*/
public void shareCookies(){
Object store = getCookieStore();
if (store == null){
store = new BasicCookieStore();
this.getParametersInner().put(HttpClientTask.PARAM_HTTP_COOKIES, store);
}
CookieStore cookieStore = (CookieStore)store;
for (Cookie cookie : this.getDriver().manage().getCookies()){
BasicClientCookie newCookie = new BasicClientCookie(cookie.getName(), cookie.getValue());
newCookie.setDomain(cookie.getDomain());
newCookie.setPath(cookie.getPath());
newCookie.setExpiryDate(cookie.getExpiry());
newCookie.setSecure(cookie.isSecure());
cookieStore.addCookie(newCookie);
}
}
示例11: 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
}
示例12: create
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
final CookieStore cookieStore = new BasicCookieStore();
// Populate cookies if needed
final BasicClientCookie cookie = new BasicClientCookie("name", "value");
cookie.setVersion(0);
cookie.setDomain(".mycompany.com");
cookie.setPath("/");
cookieStore.addCookie(cookie);
final DefaultHttpClient httpClient = super.create(method, uri);
httpClient.setCookieStore(cookieStore);
return httpClient;
}
示例13: 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)));
}
示例14: 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;
}
示例15: 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);
}
}
}