当前位置: 首页>>代码示例>>Java>>正文


Java HttpClient类代码示例

本文整理汇总了Java中cz.msebera.android.httpclient.client.HttpClient的典型用法代码示例。如果您正苦于以下问题:Java HttpClient类的具体用法?Java HttpClient怎么用?Java HttpClient使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


HttpClient类属于cz.msebera.android.httpclient.client包,在下文中一共展示了HttpClient类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: get

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
public static Hostplace get(String ip) throws Exception {
    HttpGet httppost = new HttpGet(Geocode.url + "/" + ip);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        if (json.getString("status").equals("fail"))
            throw new Exception();

        Hostplace hostplace = Hostplace.getJson(json);
        return hostplace;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:22,代码来源:Geocode.java

示例2: getBlock

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
public static Block getBlock(String blockhash) throws Exception {
    HttpGet httppost = new HttpGet(Insight.url + "/block/" + blockhash);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        Block block = Block.getJson(json);
        return block;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:19,代码来源:Insight.java

示例3: getBlockHash

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
public static String getBlockHash(String height) throws Exception {
    HttpGet httppost = new HttpGet(Insight.url + "/block-index/" + height);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        String hash = json.getString("blockHash");
        return hash;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:19,代码来源:Insight.java

示例4: getTx

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
public static Tx getTx(String hash) throws Exception {
    HttpGet httppost = new HttpGet(Insight.url + "/tx/" + hash);
    HttpClient httpclient = new DefaultHttpClient();
    HttpResponse response = httpclient.execute(httppost);

    // StatusLine stat = response.getStatusLine();
    int status = response.getStatusLine().getStatusCode();

    if (status == 200) {
        HttpEntity entity = response.getEntity();
        String data = EntityUtils.toString(entity);

        JSONObject json = new JSONObject(data);
        Tx tx = Tx.getJson(json);
        return tx;
    }
    throw new Exception();
}
 
开发者ID:lvaccaro,项目名称:BitcoinBlockExplorer,代码行数:19,代码来源:Insight.java

示例5: getFormValues

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
public static List<Pair<String, String>> getFormValues(String url, HttpRequestModel requestModel, CancellableTask task, HttpClient client,
        String startForm, String endForm) throws Exception {
    VichanAntiBot reader = null;
    HttpRequestModel request = requestModel;
    HttpResponseModel response = null;
    try {
        response = HttpStreamer.getInstance().getFromUrl(url, request, client, null, task);
        reader = new VichanAntiBot(response.stream, startForm, endForm);
        return reader.readForm();
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception e) {}
        }
        if (response != null) response.release();
    } 
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:19,代码来源:AbstractVichanModule.java

示例6: checkAntiDDOS

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
/**
 * Пройти анти-ддос проверку cloudflare
 * @param exception Cloudflare исключение
 * @param httpClient HTTP клиент
 * @param task отменяемая задача
 * @param activity активность, в контексте которого будет запущен WebView (webkit)
 * @return полученная cookie или null, если проверка не прошла по таймауту, или проверка уже проходит в другом потоке
 */
public Cookie checkAntiDDOS(CloudflareException exception, HttpClient httpClient, CancellableTask task, Activity activity) {
    if (exception.isRecaptcha()) throw new IllegalArgumentException();
    
    HttpHost proxy = null;
    if (httpClient instanceof ExtendedHttpClient) {
        proxy = ((ExtendedHttpClient) httpClient).getProxy();
    } else if (httpClient != null) {
        try {
            proxy = ConnRouteParams.getDefaultProxy(httpClient.getParams());
        } catch (Exception e) { /*ignore*/ }
    }
    if (proxy != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        if (httpClient instanceof ExtendedHttpClient) {
            return InterceptingAntiDDOS.getInstance().check(exception, (ExtendedHttpClient) httpClient, task, activity);
        } else {
            throw new IllegalArgumentException(
                    "cannot run anti-DDOS checking with proxy settings; http client is not instance of ExtendedHttpClient");
        }
    } else {
        return checkAntiDDOS(exception, proxy, task, activity);
    }
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:31,代码来源:CloudflareChecker.java

示例7: getChallenge

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
static String getChallenge(String publicKey, CancellableTask task, HttpClient httpClient, String scheme) throws Exception {
    if (scheme == null) scheme = "http";
    String response = HttpStreamer.getInstance().getStringFromUrl(scheme + RECAPTCHA_CHALLENGE_URL + publicKey,
            HttpRequestModel.DEFAULT_GET, httpClient, null, task, false);
    Matcher matcher = CHALLENGE_FIRST_PATTERN.matcher(response);
    if (matcher.find()) {
        String challenge = matcher.group(1);
        try {
            response = HttpStreamer.getInstance().getStringFromUrl(scheme + RECAPTCHA_RELOAD_URL + challenge + "&k=" + publicKey,
                    HttpRequestModel.DEFAULT_GET, httpClient, null, task, false);
            matcher = CHALLENGE_RELOAD_PATTERN.matcher(response);
            if (matcher.find()) {
                String newChallenge = matcher.group(1);
                if (newChallenge != null && newChallenge.length() > 0) return newChallenge;
            }
        } catch (Exception e) {
            Logger.e(TAG, e);
        }
        
        return challenge;
    }
    throw new RecaptchaException("can't parse recaptcha challenge answer");
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:24,代码来源:RecaptchaNoscript.java

示例8: createMyHttpClient

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
public static HttpClient createMyHttpClient() {
	try {
		KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
		trustStore.load(null, null);

		SSLSocketFactory mSSLSocketFactory = new IgnoreSSLSocketFactory(trustStore);
		mSSLSocketFactory.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);

		HttpParams params = new BasicHttpParams();
		HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
		HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);

		SchemeRegistry registry = new SchemeRegistry();
		registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
		registry.register(new Scheme("https", mSSLSocketFactory, 443));

		ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
		return new DefaultHttpClient(ccm, params);
	} catch (KeyStoreException | NoSuchAlgorithmException | IOException | CertificateException | KeyManagementException | UnrecoverableKeyException e) {
		e.printStackTrace();
	}
	return new DefaultHttpClient();
}
 
开发者ID:hiking93,项目名称:NCU-WLAN-Login,代码行数:24,代码来源:IgnoreSSLSocketFactory.java

示例9: getAsyncHttpClient

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
@Override
public AsyncHttpClient getAsyncHttpClient() {
    AsyncHttpClient ahc = super.getAsyncHttpClient();
    HttpClient client = ahc.getHttpClient();
    if (client instanceof DefaultHttpClient) {
        Toast.makeText(this,
                String.format("redirects: %b\nrelative redirects: %b\ncircular redirects: %b",
                        enableRedirects, enableRelativeRedirects, enableCircularRedirects),
                Toast.LENGTH_SHORT
        ).show();
        ahc.setEnableRedirects(enableRedirects, enableRelativeRedirects, enableCircularRedirects);
    }
    return ahc;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:Redirect302Sample.java

示例10: getHtmlConsolePage

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
private static String getHtmlConsolePage(String dev_acc, CookieStore cookieStore) throws IOException, NetworkException {
    HttpGet get = new HttpGet(Utils.DEVELOPER_CONSOLE_URL + "?dev_acc=" + dev_acc);

    HttpClient client = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();

    HttpResponse resp = client.execute(get);
    StatusLine sl = resp.getStatusLine();
    if (sl.getStatusCode() != 200) throw new NetworkException(sl);

    return EntityUtils.toString(resp.getEntity(), Charset.forName("UTF-8"));
}
 
开发者ID:devgianlu,项目名称:PlayConsoleAndroidAPI,代码行数:12,代码来源:PlayConsoleAuthenticator.java

示例11: doInBackground

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
@Override
protected Void doInBackground(String... message) {
    // Create a new HttpClient and Post Header
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("http://www.instruman.it/assets/feedback/update.php");

    try {
        //add data
        List<NameValuePair> nameValuePairs = new ArrayList<>(1);
        nameValuePairs.add(new BasicNameValuePair("stars", message[0]));
        nameValuePairs.add(new BasicNameValuePair("message", message[1]));
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        //execute http post
        HttpResponse response = httpclient.execute(httppost);

    } catch (Exception e) {

    }
    return null;
}
 
开发者ID:paolo-optc,项目名称:optc-mobile-db,代码行数:21,代码来源:FeedbackDialogFragment.java

示例12: getClient

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
@Override
protected HttpClient getClient() {
    if (httpClient == null) {
        synchronized (this) {
            if (httpClient == null) {
                httpClient = build(proxy, getCookieStore());
            }
        }
    }
    return httpClient;
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:12,代码来源:ExtendedHttpClient.java

示例13: build

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
private static HttpClient build(final HttpHost proxy, CookieStore cookieStore) {
    SSLCompatibility.waitIfInstallingAsync();
    return HttpClients.custom().
            setDefaultRequestConfig(getDefaultRequestConfigBuilder(HttpConstants.DEFAULT_HTTP_TIMEOUT).build()).
            setUserAgent(HttpConstants.USER_AGENT_STRING).
            setProxy(proxy).
            setDefaultCookieStore(cookieStore).
            setSSLSocketFactory(ExtendedSSLSocketFactory.getSocketFactory()).
            build();
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:11,代码来源:ExtendedHttpClient.java

示例14: close

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
@Override
public void close() throws IOException {
    HttpClient client = getClient();
    if (client instanceof Closeable) {
        ((Closeable) client).close();
    }
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:8,代码来源:HttpClientWrapper.java

示例15: getChallenge

import cz.msebera.android.httpclient.client.HttpClient; //导入依赖的package包/类
static String getChallenge(String key, CancellableTask task, HttpClient httpClient, String scheme) throws Exception {
    if (scheme == null) scheme = "http";
    String address = scheme + "://127.0.0.1/";
    String data = "<script type=\"text/javascript\"> " +
                      "var RecaptchaOptions = { " +
                          "theme : 'custom', " +
                          "custom_theme_widget: 'recaptcha_widget' " +
                      "}; " +
                  "</script>" +
                  "<div id=\"recaptcha_widget\" style=\"display:none\"> " +
                      "<div id=\"recaptcha_image\"></div> " +
                      "<input type=\"text\" id=\"recaptcha_response_field\" name=\"recaptcha_response_field\" /> " +
                  "</div>" +
                  "<script type=\"text/javascript\" src=\"" + scheme + "://www.google.com/recaptcha/api/challenge?k=" + key + "\"></script>";
    
    HttpHost proxy = null;
    if (httpClient instanceof ExtendedHttpClient) {
        proxy = ((ExtendedHttpClient) httpClient).getProxy();
    } else if (httpClient != null) {
        try {
            proxy = ConnRouteParams.getDefaultProxy(httpClient.getParams());
        } catch (Exception e) { /*ignore*/ }
    }
    if (proxy != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        return Intercepting.getInternal(address, data, task, httpClient);
    } else {
        return getChallengeInternal(address, data, task, proxy);
    }
}
 
开发者ID:miku-nyan,项目名称:Overchan-Android,代码行数:30,代码来源:RecaptchaAjax.java


注:本文中的cz.msebera.android.httpclient.client.HttpClient类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。