本文整理匯總了Java中org.apache.http.impl.cookie.BasicClientCookie.setAttribute方法的典型用法代碼示例。如果您正苦於以下問題:Java BasicClientCookie.setAttribute方法的具體用法?Java BasicClientCookie.setAttribute怎麽用?Java BasicClientCookie.setAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.impl.cookie.BasicClientCookie
的用法示例。
在下文中一共展示了BasicClientCookie.setAttribute方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: makeCookie
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
/**
* Create an HttpClient cookie from a JMeter cookie
*/
private org.apache.http.cookie.Cookie makeCookie(Cookie jmc) {
long exp = jmc.getExpiresMillis();
BasicClientCookie ret = new BasicClientCookie(jmc.getName(),
jmc.getValue());
ret.setDomain(jmc.getDomain());
ret.setPath(jmc.getPath());
ret.setExpiryDate(exp > 0 ? new Date(exp) : null); // use null for no expiry
ret.setSecure(jmc.getSecure());
ret.setVersion(jmc.getVersion());
if(jmc.isDomainSpecified()) {
ret.setAttribute(ClientCookie.DOMAIN_ATTR, jmc.getDomain());
}
if(jmc.isPathSpecified()) {
ret.setAttribute(ClientCookie.PATH_ATTR, jmc.getPath());
}
return ret;
}
示例2: 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;
}
示例3: createCookie
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
public static Cookie createCookie(String name, String value) {
final BasicClientCookie cookie = new BasicClientCookie(name, value);
cookie.setAttribute(ClientCookie.DOMAIN_ATTR, Const.COOKIE_DOMAIN);
cookie.setPath("/");
cookie.setDomain(Const.COOKIE_DOMAIN);
return cookie;
}
示例4: createCookieForHeaderElement
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
/**
* This method will create a {@link BasicClientCookie} with the given {@link HeaderElement}.
* It sill set the cookie's name and value according to the {@link HeaderElement#getName()} and {@link HeaderElement#getValue()} methods.
* Moreover, it will transport every {@link HeaderElement} parameter to the cookie using the {@link BasicClientCookie#setAttribute(String, String)}.
* Additionally, it configures the cookie path ({@link BasicClientCookie#setPath(String)}) to value '/client/api' and the cookie domain using {@link #configureDomainForCookie(BasicClientCookie)} method.
*/
protected BasicClientCookie createCookieForHeaderElement(HeaderElement element) {
BasicClientCookie cookie = new BasicClientCookie(element.getName(), element.getValue());
for (NameValuePair parameter : element.getParameters()) {
cookie.setAttribute(parameter.getName(), parameter.getValue());
}
cookie.setPath("/client/api");
configureDomainForCookie(cookie);
return cookie;
}
示例5: retrieveWsdl
import org.apache.http.impl.cookie.BasicClientCookie; //導入方法依賴的package包/類
static void retrieveWsdl(final Context context, final HttpGet httpGet, final String wsdlFileName) throws Exception {
final BasicClientCookie cookie = new BasicClientCookie("sid", context.loginContext.getSessionId());
cookie.setDomain(".salesforce.com");
cookie.setAttribute(ClientCookie.DOMAIN_ATTR, "true");
CookieStore cookieStore = new BasicCookieStore();
cookieStore.addCookie(cookie);
HttpContext localContext = new BasicHttpContext();
localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
final String outputFile = StringUtils.concatWithSeparator(false, System.getProperty("file.separator"), context.outputDir, context.prefix + wsdlFileName);
System.out.println("Retreiving [" + outputFile + "]");
CloseableHttpResponse loginResponse = HttpClients.createDefault().execute(httpGet, localContext);
final FileWriter writer = new FileWriter(outputFile);
IOUtils.copy(loginResponse.getEntity().getContent(), writer);
writer.close();
loginResponse.close();
}