• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java AsyncHttpGet类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: testMaxAgePrivate

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testMaxAgePrivate() throws Exception {
    AsyncHttpClient client = new AsyncHttpClient(AsyncServer.getDefault());
    ResponseCacheMiddleware cache = ResponseCacheMiddleware.addCache(client, new File(getContext().getFilesDir(), "AndroidAsyncTest"), 1024 * 1024 * 10);
    AsyncHttpServer httpServer = new AsyncHttpServer();
    try {
        httpServer.get("/uname/(.*)", new HttpServerRequestCallback() {
            @Override
            public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
                response.getHeaders().set("Date", HttpDate.format(new Date()));
                response.getHeaders().set("Cache-Control", "private, max-age=10000");
                response.send(request.getMatcher().group(1));
            }
        });

        AsyncServerSocket socket = httpServer.listen(AsyncServer.getDefault(), 0);
        int port = socket.getLocalPort();
        // clear the old cache
        cache.clear();

        client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();

        client.executeString(new AsyncHttpGet("http://localhost:" + port + "/uname/43434"), null).get();


        assertEquals(cache.getCacheHitCount(), 1);
        assertEquals(cache.getNetworkCount(), 1);
    }
    finally {
        AsyncServer.getDefault().stop();
        client.getMiddleware().remove(cache);
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:33,代码来源:CacheTests.java


示例2: testRelativeRedirect

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testRelativeRedirect() throws Exception {
    String ret = AsyncHttpClient.getDefaultInstance()
    .executeString(new AsyncHttpGet("http://localhost:6003/foo/bar"), null)
    .get();

    assertEquals(ret, "SUCCESS!");

    ret = AsyncHttpClient.getDefaultInstance()
    .executeString(new AsyncHttpGet("http://localhost:6003/foo"), null)
    .get();

    assertEquals(ret, "BORAT!");

    ret = AsyncHttpClient.getDefaultInstance()
    .executeString(new AsyncHttpGet("http://localhost:6003/foo/poo"), null)
    .get();

    assertEquals(ret, "SWEET!");
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:20,代码来源:RedirectTests.java


示例3: executeGet

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public static Future<?> executeGet(Request request, final ResponseCallback responseCallback) {
    StringBuilder stringBuffer = new StringBuilder(request.getURL());
    if (request.getURLParams() != null) {
        String params = HttpUtils.getRequestParams(request.getURLParams());
        if (!TextUtils.isEmpty(params)) {
            stringBuffer.append("?").append(params);
        }
    }
    if (BuildConfig.DEBUG) {
        LogUtils.d(stringBuffer.toString());
    }
    AsyncHttpGet asyncHttpGet = new AsyncHttpGet(stringBuffer.toString());
    CacheControl cacheControl = request.getCacheControl();
    if (cacheControl != null) {
        asyncHttpGet.setHeader("Cache-Control", cacheControl.getCacheHeaderProperty());
    }
    addHead(request.getHeader(), asyncHttpGet);
    return asyncHttpClient.executeString(asyncHttpGet, new AsyncHttpClient.StringCallback() {
        @Override
        public void onCompleted(Exception e, AsyncHttpResponse asyncHttpResponse, String s) {
            if (responseCallback != null) {
                responseCallback.onCompleted(e, asyncHttpResponse, s);
            }
        }
    });
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:27,代码来源:HttpApi.java


示例4: doLongPolling

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
private void doLongPolling() {
    this.client.executeString(new AsyncHttpGet(computedRequestUrl()), new AsyncHttpClient.StringCallback() {
        @Override
        public void onCompleted(Exception e, AsyncHttpResponse source, String result) {
            if (e != null) {
                close(e);
                return;
            }

            sendResult(result);
            doLongPolling();
        }
    });
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:15,代码来源:XHRPollingTransport.java


示例5: testGithubHelloWithFutureCallback

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testGithubHelloWithFutureCallback() throws Exception {
    final Semaphore semaphore = new Semaphore(0);
    client.executeString(new AsyncHttpGet("https://" + githubPath + "hello.txt"), null)
    .setCallback(new FutureCallback<String>() {
        @Override
        public void onCompleted(Exception e, String result) {
            assertEquals(result, "hello world");
            semaphore.release();
        }
    });
    assertTrue("timeout", semaphore.tryAcquire(TIMEOUT, TimeUnit.MILLISECONDS));
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:13,代码来源:HttpClientTests.java


示例6: testProxy

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testProxy() throws Exception {
        wasProxied = false;
        final AsyncServer proxyServer = new AsyncServer();
        try {
            AsyncProxyServer httpServer = new AsyncProxyServer(proxyServer) {
                @Override
                protected boolean onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
                    wasProxied = true;
                    return super.onRequest(request, response);
                }
            };

            AsyncServerSocket socket = httpServer.listen(proxyServer, 0);

//            client.getSocketMiddleware().enableProxy("localhost", 5555);

            AsyncHttpGet get = new AsyncHttpGet("http://www.clockworkmod.com");
            get.enableProxy("localhost", socket.getLocalPort());

            Future<String> ret = client.executeString(get, null);
            String data;
            assertNotNull(data = ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
            assertTrue(data.contains("ClockworkMod"));
            assertTrue(wasProxied);
        }
        finally {
            proxyServer.stop();
        }
    }
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:30,代码来源:HttpClientTests.java


示例7: testKeys

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testKeys() throws Exception {
    KeyManagerFactory kmf = KeyManagerFactory.getInstance("X509");
    KeyStore ks = KeyStore.getInstance(KeyStore.getDefaultType());

    ks.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
    kmf.init(ks, "storepass".toCharArray());


    TrustManagerFactory tmf = TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
    KeyStore ts = KeyStore.getInstance(KeyStore.getDefaultType());
    ts.load(getContext().getResources().openRawResource(R.raw.keystore), "storepass".toCharArray());
    tmf.init(ts);

    SSLContext sslContext = SSLContext.getInstance("TLS");
    sslContext.init(kmf.getKeyManagers(), tmf.getTrustManagers(), null);

    AsyncHttpServer httpServer = new AsyncHttpServer();
    httpServer.listenSecure(8888, sslContext);
    httpServer.get("/", new HttpServerRequestCallback() {
        @Override
        public void onRequest(AsyncHttpServerRequest request, AsyncHttpServerResponse response) {
            response.send("hello");
        }
    });

    Thread.sleep(1000);

    AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setSSLContext(sslContext);
    AsyncHttpClient.getDefaultInstance().getSSLSocketMiddleware().setTrustManagers(tmf.getTrustManagers());
    AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet("https://localhost:8888/"), null).get();
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:32,代码来源:SSLTests.java


示例8: disabled__testClientCertificateIssue163

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void disabled__testClientCertificateIssue163() throws Exception {
    // https://security.springthroughtest.com/hello.json

    AsyncServer server = new AsyncServer();
    try {
        AsyncHttpClient client = new AsyncHttpClient(server);
        JSONObject json = client.executeJSONObject(new AsyncHttpGet("https://security.springthroughtest.com/hello.json"), null).get();

    }
    finally {
        server.stop();
    }
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:14,代码来源:SSLTests.java


示例9: shareMyApp

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void  shareMyApp()
{
    String title ="精彩分享";
    String desc  = "我也有自己的App了:)";

    String url =
  FlyingDataManager.getServerNetAddress() +
  "/aa_get_app_info_from_hp.action?app_id=" +
  FlyingDataManager.getBirdcopyAppID() +
  "&type=page";

    try
    {
        String webURL= AsyncHttpClient.getDefaultInstance().executeString(new AsyncHttpGet(url),null).get();

        Intent shareIntent = new Intent(Intent.ACTION_SEND);
        shareIntent.setType("text/plain");

        shareIntent.putExtra(Intent.EXTRA_TITLE,  "分享精彩");
        shareIntent.putExtra(Intent.EXTRA_SUBJECT, title);
        shareIntent.putExtra(Intent.EXTRA_TEXT, title +"\n"+desc+"\n"+webURL);
        startActivity(Intent.createChooser(shareIntent, "分享精彩"));

        awardCoin();
        //MyApplication.getInstance().playCoinSound();
    }
    catch (Exception e)
    {
    }
}
 
开发者ID:birdcopy,项目名称:Android-Birdcopy-Application,代码行数:31,代码来源:MainActivity.java


示例10: get

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void get(String regex, HttpServerRequestCallback callback) {
    addAction(AsyncHttpGet.METHOD, regex, callback);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:4,代码来源:AsyncHttpServer.java


示例11: onBodyDecoder

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
@Override
public void onBodyDecoder(OnBodyDataOnRequestSentData data) {
    CachedSocket cached = com.koushikdutta.async.Util.getWrappedSocket(data.socket, CachedSocket.class);
    if (cached != null) {
        data.response.headers().set(SERVED_FROM, CACHE);
        return;
    }

    CacheData cacheData = data.state.get("cache-data");
    RawHeaders rh = RawHeaders.fromMultimap(data.response.headers().getMultiMap());
    rh.removeAll("Content-Length");
    rh.setStatusLine(String.format(Locale.ENGLISH, "%s %s %s", data.response.protocol(), data.response.code(), data.response.message()));
    ResponseHeaders networkResponse = new ResponseHeaders(data.request.getUri(), rh);
    data.state.put("response-headers", networkResponse);
    if (cacheData != null) {
        if (cacheData.cachedResponseHeaders.validate(networkResponse)) {
            data.request.logi("Serving response from conditional cache");
            ResponseHeaders combined = cacheData.cachedResponseHeaders.combine(networkResponse);
            data.response.headers(new Headers(combined.getHeaders().toMultimap()));
            data.response.code(combined.getHeaders().getResponseCode());
            data.response.message(combined.getHeaders().getResponseMessage());

            data.response.headers().set(SERVED_FROM, CONDITIONAL_CACHE);
            conditionalCacheHitCount++;

            CachedBodyEmitter bodySpewer = new CachedBodyEmitter(cacheData.candidate, cacheData.contentLength);
            bodySpewer.setDataEmitter(data.bodyEmitter);
            data.bodyEmitter = bodySpewer;
            bodySpewer.sendCachedData();
            return;
        }

        // did not validate, so fall through and cache the response
        data.state.remove("cache-data");
        StreamUtility.closeQuietly(cacheData.snapshot);
    }

    if (!caching)
        return;

    RequestHeaders requestHeaders = data.state.get("request-headers");
    if (requestHeaders == null || !networkResponse.isCacheable(requestHeaders) || !data.request.getMethod().equals(AsyncHttpGet.METHOD)) {
        /*
         * Don't cache non-GET responses. We're technically allowed to cache
         * HEAD requests and some POST requests, but the complexity of doing
         * so is high and the benefit is low.
         */
        networkCount++;
        data.request.logd("Response is not cacheable");
        return;
    }

    String key = FileCache.toKeyString(data.request.getUri());
    RawHeaders varyHeaders = requestHeaders.getHeaders().getAll(networkResponse.getVaryFields());
    Entry entry = new Entry(data.request.getUri(), varyHeaders, data.request, networkResponse.getHeaders());
    BodyCacher cacher = new BodyCacher();
    EntryEditor editor = new EntryEditor(key);
    try {
        entry.writeTo(editor);
        // create the file
        editor.newOutputStream(ENTRY_BODY);
    }
    catch (Exception e) {
        // Log.e(LOGTAG, "error", e);
        editor.abort();
        networkCount++;
        return;
    }
    cacher.editor = editor;

    cacher.setDataEmitter(data.bodyEmitter);
    data.bodyEmitter = cacher;

    data.state.put("body-cacher", cacher);
    data.request.logd("Caching response");
    cacheStoreCount++;
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:78,代码来源:ResponseCacheMiddleware.java


示例12: testHomepage

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testHomepage() throws Exception {
    Future<String> ret = client.executeString(new AsyncHttpGet("http://google.com"), null);
    assertNotNull(ret.get(TIMEOUT, TimeUnit.MILLISECONDS));
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:5,代码来源:HttpClientTests.java


示例13: testGithubRandomDataWithFuture

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testGithubRandomDataWithFuture() throws Exception {
    final Md5 md5 = Md5.createInstance();
    Future<ByteBufferList> bb = client.executeByteBufferList(new AsyncHttpGet(github), null);
    md5.update(bb.get(TIMEOUT, TimeUnit.MILLISECONDS));
    assertEquals(md5.digest(), dataNameAndHash);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:7,代码来源:HttpClientTests.java


示例14: testGithubHelloWithFuture

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testGithubHelloWithFuture() throws Exception {
    Future<String> string = client.executeString(new AsyncHttpGet("https://" + githubPath + "hello.txt"), null);
    assertEquals(string.get(TIMEOUT, TimeUnit.MILLISECONDS), "hello world");
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:5,代码来源:HttpClientTests.java


示例15: testUriPathWithSpaces

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testUriPathWithSpaces() throws Exception {
    AsyncHttpRequest request = new AsyncHttpRequest(Uri.parse("http://jpkc.seiee.sjtu.edu.cn/ds/ds2/Course%20lecture/chapter%2010.pdf"), AsyncHttpGet.METHOD);
    String requestLine = request.getRequestLine().toString();
    assertEquals("GET /ds/ds2/Course%20lecture/chapter%2010.pdf HTTP/1.1", requestLine);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:6,代码来源:HttpClientTests.java


示例16: disabledTestSSLProxy

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
private void disabledTestSSLProxy() throws Exception {
    AsyncHttpGet get = new AsyncHttpGet("http://yahoo.com");
    get.enableProxy("192.168.2.21", 8888);
    get.setLogging("SSLProxy", Log.VERBOSE);
    String ret = AsyncHttpClient.getDefaultInstance().executeString(get, null).get(5000, TimeUnit.DAYS.MILLISECONDS);
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:7,代码来源:ProxyTests.java


示例17: testIon428

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
public void testIon428() throws Exception {
    ByteBufferList bb = AsyncHttpClient.getDefaultInstance().executeByteBufferList(new AsyncHttpGet("https://cdn2.vox-cdn.com/thumbor/KxtZNw37jKNfxdA0hX5edHvbTBE=/0x0:2039x1359/800x536/cdn0.vox-cdn.com/uploads/chorus_image/image/44254028/lg-g-watch.0.0.jpg"), null)
    .get();
}
 
开发者ID:jacklongway,项目名称:LiteSDK,代码行数:5,代码来源:Issue59.java


示例18: onBodyDecoder

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
@Override
public void onBodyDecoder(OnBodyDataOnRequestSentData data) {
    CachedSocket cached = com.koushikdutta.async.Util.getWrappedSocket(data.socket, CachedSocket.class);
    if (cached != null) {
        data.response.headers().set(SERVED_FROM, CACHE);
        return;
    }

    CacheData cacheData = data.state.get("cache-data");
    RawHeaders rh = RawHeaders.fromMultimap(data.response.headers().getMultiMap());
    rh.removeAll("Content-Length");
    rh.setStatusLine(String.format("%s %s %s", data.response.protocol(), data.response.code(), data.response.message()));
    ResponseHeaders networkResponse = new ResponseHeaders(data.request.getUri(), rh);
    data.state.put("response-headers", networkResponse);
    if (cacheData != null) {
        if (cacheData.cachedResponseHeaders.validate(networkResponse)) {
            data.request.logi("Serving response from conditional cache");
            ResponseHeaders combined = cacheData.cachedResponseHeaders.combine(networkResponse);
            data.response.headers(new Headers(combined.getHeaders().toMultimap()));
            data.response.code(combined.getHeaders().getResponseCode());
            data.response.message(combined.getHeaders().getResponseMessage());

            data.response.headers().set(SERVED_FROM, CONDITIONAL_CACHE);
            conditionalCacheHitCount++;

            CachedBodyEmitter bodySpewer = new CachedBodyEmitter(cacheData.candidate, cacheData.contentLength);
            bodySpewer.setDataEmitter(data.bodyEmitter);
            data.bodyEmitter = bodySpewer;
            bodySpewer.sendCachedData();
            return;
        }

        // did not validate, so fall through and cache the response
        data.state.remove("cache-data");
        StreamUtility.closeQuietly(cacheData.snapshot);
    }

    if (!caching)
        return;

    RequestHeaders requestHeaders = data.state.get("request-headers");
    if (requestHeaders == null || !networkResponse.isCacheable(requestHeaders) || !data.request.getMethod().equals(AsyncHttpGet.METHOD)) {
        /*
         * Don't cache non-GET responses. We're technically allowed to cache
         * HEAD requests and some POST requests, but the complexity of doing
         * so is high and the benefit is low.
         */
        networkCount++;
        data.request.logd("Response is not cacheable");
        return;
    }

    String key = FileCache.toKeyString(data.request.getUri());
    RawHeaders varyHeaders = requestHeaders.getHeaders().getAll(networkResponse.getVaryFields());
    Entry entry = new Entry(data.request.getUri(), varyHeaders, data.request, networkResponse.getHeaders());
    BodyCacher cacher = new BodyCacher();
    EntryEditor editor = new EntryEditor(key);
    try {
        entry.writeTo(editor);
        // create the file
        editor.newOutputStream(ENTRY_BODY);
    }
    catch (Exception e) {
        // Log.e(LOGTAG, "error", e);
        editor.abort();
        networkCount++;
        return;
    }
    cacher.editor = editor;

    cacher.setDataEmitter(data.bodyEmitter);
    data.bodyEmitter = cacher;

    data.state.put("body-cacher", cacher);
    data.request.logd("Caching response");
    cacheStoreCount++;
}
 
开发者ID:BeckNiu,项目名称:MyCar,代码行数:78,代码来源:ResponseCacheMiddleware.java


示例19: createGetRequest

import com.koushikdutta.async.http.AsyncHttpGet; //导入依赖的package包/类
AsyncHttpRequest createGetRequest() {
    return new AsyncHttpGet(createEndpointUri());
}
 
开发者ID:lavong,项目名称:SpockUnitTestsDemo,代码行数:4,代码来源:ContactsProvider.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CompiledVFrame类代码示例发布时间:2022-05-23
下一篇:
Java GridWorldDomain类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap