下面列出了怎么用org.apache.http.client.protocol.ClientContext的API类实例代码及写法,或者点击链接到github查看源代码。
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider = (CredentialsProvider) context
.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authScheme != null) {
Credentials creds = credsProvider
.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
}
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
if (authState.getAuthScheme() != null || authState.hasAuthOptions()) {
return;
}
// If no authState has been established and this is a PUT or POST request, add preemptive authorisation
String requestMethod = request.getRequestLine().getMethod();
if (requestMethod.equals(HttpPut.METHOD_NAME) || requestMethod.equals(HttpPost.METHOD_NAME)) {
CredentialsProvider credentialsProvider = (CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
Credentials credentials = credentialsProvider.getCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()));
if (credentials == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, credentials);
}
}
@Override
public void process(HttpRequest request, HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
Credentials creds;
if (authState.getAuthScheme() == null) {
AuthScheme authScheme = (AuthScheme) context.getAttribute("preemptive-auth");
CredentialsProvider credsProvider =
(CredentialsProvider) context.getAttribute(ClientContext.CREDS_PROVIDER);
HttpHost targetHost =
(HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authScheme != null) {
creds =
credsProvider.getCredentials(new AuthScope(
targetHost.getHostName(),
targetHost.getPort()));
if (creds == null) {
throw new HttpException("No credentials for preemptive authentication");
}
authState.update(authScheme, creds);
}
}
}
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 XvidStage.com");
//responseString = NUHttpClientUtils.getData("http://xvidstage.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 void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//NULogger.getLogger().info("Getting startup cookies & link from Vip-File.com");
//responseString = NUHttpClientUtils.getData("http://vip-file.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 VodLocker.com");
//responseString = NUHttpClientUtils.getData("http://vodlocker.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 FileOM.com");
//responseString = NUHttpClientUtils.getData("http://fileom.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 PutStream.com");
//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 FileCloud.cc");
//responseString = NUHttpClientUtils.getData("http://filecloud.cc", 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 RockFile.eu");
//responseString = NUHttpClientUtils.getData("http://rockfile.eu", httpContext);
}
@Override
public void run() {
uploadInitialising();
try{
if (fireDriveAccount.loginsuccessful) {
httpContext = fireDriveAccount.getHttpContext();
if(fireDriveAccount.isPremium()){
maxFileSizeLimit = 53687091200l; //50 GB
}
else{
maxFileSizeLimit = 1073741824l; //1 GB
}
}
else{
httpContext.setAttribute(ClientContext.COOKIE_STORE, new BasicCookieStore());
}
if (file.length() > maxFileSizeLimit) {
throw new NUMaxFileSizeException(maxFileSizeLimit, file.getName(), getHost());
}
normalUpload();
uploadFinished();
} catch(NUException ex){
ex.printError();
uploadInvalid();
} catch(Exception e){
NULogger.getLogger().log(Level.INFO, "Exception: {0}", e);
uploadFailed();
}
}
public void process(final HttpRequest request, final HttpContext context) throws HttpException, IOException {
AuthState authState = (AuthState) context.getAttribute(ClientContext.TARGET_AUTH_STATE);
CredentialsProvider credsProvider = (CredentialsProvider) context.getAttribute(
ClientContext.CREDS_PROVIDER);
HttpHost targetHost = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
if (authState.getAuthScheme() == null) {
AuthScope authScope = new AuthScope(targetHost.getHostName(), targetHost.getPort());
Credentials creds = credsProvider.getCredentials(authScope);
if (creds != null) {
authState.setAuthScheme(new BasicScheme());
authState.setCredentials(creds);
}
}
}
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 HugeFiles.net");
//responseString = NUHttpClientUtils.getData("http://hugefiles.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 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 VozUpload.com");
//responseString = NUHttpClientUtils.getData("http://vozupload.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 UploadRocket.net");
//responseString = NUHttpClientUtils.getData("http://uploadrocket.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 MegaCache.net");
//responseString = NUHttpClientUtils.getData("http://megacache.net", httpContext);
}
/**
* There is a cookie that starts with this name?
* @param httpContext the context.
* @param name the first part of the name of the cookie.
* @return boolean value.
*/
public static boolean existCookieStartWithValue(HttpContext httpContext, String name){
CookieStore cookieStore = (CookieStore) httpContext.getAttribute(ClientContext.COOKIE_STORE);
List<Cookie> cookies = cookieStore.getCookies();
String cookieName;
for(int i = 0; i < cookies.size(); i++){
cookieName = cookies.get(i).getName();
if(cookieName.startsWith(name)){
return true;
}
}
return false;
}
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 UploadBoy.com");
//responseString = NUHttpClientUtils.getData("http://uploadboy.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 2Drive.net");
//responseString = NUHttpClientUtils.getData("2Drive.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 SafeSharing.eu");
//responseString = NUHttpClientUtils.getData("http://safesharing.eu", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("** CloudCorner.com ** => Gathering initial cookie values.");
responseString = NUHttpClientUtils.getData("https://www.cloudcorner.com/", httpContext);
responseString = NUHttpClientUtils.getData("https://www.cloudcorner.com/api/recaptcha", httpContext);
// {"success":true,"data":{"enable":true,"key":"6Ld7c9ISAAAAADeAGevtJ0zpz4nfVmjUNt5-Caqh"}}
if (StringUtils.stringBetweenTwoStrings(responseString, "\"enable\":", ",\"").equals("true")){
isCaptReq = true;
NULogger.getLogger().info("** CloudCorner.com ** => Captcha is being enforced ...");
kChallengeCode = StringUtils.stringBetweenTwoStrings(responseString, "\"key\":\"", "\"");
Captcha captcha = captchaServiceProvider().newCaptcha();
captcha.setFormTitle(Translation.T().captchacontrol()+" ("+ getHOSTNAME() +")");
if(captcha.findCCaptchaUrlFromK(kChallengeURL+kChallengeCode) != null){
captcha.findCaptchaImageURL();
recaptchaChallengeField = captcha.getCCaptchaUrl();
captchaString = captcha.getCaptchaString();
NULogger.getLogger().info("** CloudCorner.com ** => Captcha string input by the user: "+captchaString);
} else {
throw new Exception("Captcha generic error");
}
}
}
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 EDisk.cz");
//responseString = NUHttpClientUtils.getData("http://www.edisk.cz", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
//Force to use en language
BasicClientCookie cookie = new BasicClientCookie("language_selection", "EN");
cookie.setDomain(".bitshare.com");
cookie.setPath("/");
cookieStore.addCookie(cookie);
//NULogger.getLogger().info("Getting startup cookies & link from BitShare.com");
//responseString = NUHttpClientUtils.getData("http://bitshare.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 FileNuke.com");
//responseString = NUHttpClientUtils.getData("http://filenuke.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 Files2Share.ch");
//responseString = NUHttpClientUtils.getData("http://files2share.ch", httpContext);
}
private void initialize() throws Exception {
httpContext = new BasicHttpContext();
cookieStore = new BasicCookieStore();
httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
NULogger.getLogger().info("** MinhaTeca.com.br ** => Initiating plugin ...");
responseString = NUHttpClientUtils.getData("http://minhateca.com.br/", httpContext);
doc = Jsoup.parse(responseString);
vToken = doc.select("input[name=__RequestVerificationToken]").attr("value");
if (!vToken.isEmpty()){
NULogger.getLogger().info("** MinhaTeca.com.br ** => Verification token found! Proceeding further.");
} else {
NULogger.getLogger().info("** MinhaTeca.com.br ** => Error! Unable to find the verification token!");
}
}
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 XfileLoad.com");
//responseString = NUHttpClientUtils.getData("http://xfileload.com", httpContext);
}