下面列出了org.apache.http.protocol.BasicHttpContext#setAttribute ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from JunoCloud.me");
//responseString = NUHttpClientUtils.getData("http://junocloud.me", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from NetU.tv");
//responseString = NUHttpClientUtils.getData("http://netu.tv", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from VidXden.com");
//responseString = NUHttpClientUtils.getData("http://vidxden.com", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from RyuShare.com");
//stringResponse = NUHttpClientUtils.getData("http://ryushare.com/", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from VidTo.me");
//responseString = NUHttpClientUtils.getData("http://vidto.me", httpContext);
}
private HttpResponse login(BonitaCredentials credentials) throws IOException {
BasicHttpContext httpContext = new BasicHttpContext();
BasicCookieStore cookieStore = new BasicCookieStore();
httpContext.setAttribute("http.cookie-store", cookieStore);
List<NameValuePair> urlParameters = new ArrayList<NameValuePair>();
urlParameters.add(new BasicNameValuePair("username", credentials.username));
urlParameters.add(new BasicNameValuePair("password", credentials.password));
urlParameters.add(new BasicNameValuePair("redirect", "false"));
UrlEncodedFormEntity entity = new UrlEncodedFormEntity(urlParameters, "utf-8");
HttpPost postRequest = new HttpPost(credentials.loginServletURI);
postRequest.setEntity(entity);
return getProxyClient().execute(postRequest, httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from FileVice.com");
//responseString = NUHttpClientUtils.getData("http://filevice.com", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from TurboVideos.net");
//responseString = NUHttpClientUtils.getData("", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from Up07.net");
//responseString = NUHttpClientUtils.getData("http://up07.net", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from FileRio.in");
//responseString = NUHttpClientUtils.getData("http://filerio.in", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from VShare.eu");
responseString = NUHttpClientUtils.getData("http://vshare.eu/login.html", httpContext);
redirect = StringUtils.stringBetweenTwoStrings(responseString, "name=\"redirect\" value=\"", "\"");
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from UsersFiles.com");
responseString = NUHttpClientUtils.getData("https://usersfiles.com/", httpContext);
doc = Jsoup.parse(responseString);
rand = doc.select("form[name=FL]").select("input[name=rand]").attr("value");
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from VideoWood.tv");
responseString = NUHttpClientUtils.getData("http://videowood.tv/login", httpContext);
doc = Jsoup.parse(responseString);
vdwood_token = doc.select("form").select("input[name=_token]").attr("value");
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from VideoMega.tv");
//responseString = NUHttpClientUtils.getData("http://videomega.tv", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("Getting startup cookies & link from UltraMegaBit.com");
responseString = NUHttpClientUtils.getData("https://ultramegabit.com/login", httpContext);
csrf_token = Jsoup.parse(responseString).select("input[name=csrf_token]").val();
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from MegaCache.net");
//responseString = NUHttpClientUtils.getData("http://megacache.net", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from Keep2Share.cc");
//responseString = NUHttpClientUtils.getData("http://keep2share.cc/", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
}
public MTGDesignPicturesProvider() throws IOException {
super();
cookieStore = new BasicCookieStore();
httpContext = new BasicHttpContext();
httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookieStore);
}
/**
* Execute a request via HTTP
*
* @param method GET, PUT, POST, DELETE, etc
* @param url The remote connection string
* @param headers HTTP headers to be sent
* @param params Parameters for the get. Can be null.
* @param inputStream Source stream for retrieving request data
* @param options Any additional options for affecting request behaviour. Can NOT be null.
* @param noChunkMaxSize The maximum size before chunking would need to be utilised. 0 disables check for chunking
* @return ResponseWrapper
* @throws Exception
*/
public static ResponseWrapper execRequest(String method, String url, Enumeration<Header> headers, NameValuePair[] params, InputStream inputStream, Map<String, String> options, long noChunkMaxSize) throws Exception {
HttpClientBuilder httpBuilder = HttpClientBuilder.create();
URL urlObj = new URL(url);
/*
* httpClient is used for this request only,
* set a connection manager that manages just one connection.
*/
if (urlObj.getProtocol().equalsIgnoreCase("https")) {
/*
* Note: registration of a custom SSLSocketFactory via httpBuilder.setSSLSocketFactory is ignored when a connection manager is set.
* The custom SSLSocketFactory needs to be registered together with the connection manager.
*/
SSLConnectionSocketFactory sslCsf = buildSslFactory(urlObj, options);
httpBuilder.setConnectionManager(new BasicHttpClientConnectionManager(RegistryBuilder.<ConnectionSocketFactory>create().register("http", PlainConnectionSocketFactory.getSocketFactory()).register("https", sslCsf).build()));
} else {
httpBuilder.setConnectionManager(new BasicHttpClientConnectionManager());
}
RequestBuilder rb = getRequestBuilder(method, urlObj, params, headers);
RequestConfig.Builder rcBuilder = buildRequestConfig(options);
setProxyConfig(httpBuilder, rcBuilder, urlObj.getProtocol());
rb.setConfig(rcBuilder.build());
if (inputStream != null) {
if (noChunkMaxSize > 0L) {
ByteArrayOutputStream bout = new ByteArrayOutputStream();
long copied = IOUtils.copyLarge(inputStream, bout, 0L, noChunkMaxSize + 1, new byte[8192]);
if (copied > noChunkMaxSize) {
throw new IOException("Mime inputstream too big to put in memory (more than " + noChunkMaxSize + " bytes).");
}
ByteArrayEntity bae = new ByteArrayEntity(bout.toByteArray(), null);
rb.setEntity(bae);
} else {
InputStreamEntity ise = new InputStreamEntity(inputStream);
rb.setEntity(ise);
}
}
final HttpUriRequest request = rb.build();
String httpUser = options.get(HTTPUtil.PARAM_HTTP_USER);
String httpPwd = options.get(HTTPUtil.PARAM_HTTP_PWD);
if (httpUser != null) {
CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(httpUser, httpPwd));
httpBuilder.setDefaultCredentialsProvider(credentialsProvider);
}
BasicHttpContext localcontext = new BasicHttpContext();
BasicScheme basicAuth = new BasicScheme();
localcontext.setAttribute("preemptive-auth", basicAuth);
try (CloseableHttpClient httpClient = httpBuilder.build()) {
ProfilerStub transferStub = Profiler.startProfile();
try (CloseableHttpResponse response = httpClient.execute(request, localcontext)) {
ResponseWrapper resp = new ResponseWrapper(response);
Profiler.endProfile(transferStub);
resp.setTransferTimeMs(transferStub.getMilliseconds());
for (org.apache.http.Header header : response.getAllHeaders()) {
resp.addHeaderLine(header.toString());
}
return resp;
}
}
}