本文整理汇总了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();
}