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


Java HttpEntity类代码示例

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


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

示例1: executeSample

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
    RequestParams params = new RequestParams();
    params.setUseJsonStreamer(true);
    JSONObject body;
    if (isRequestBodyAllowed() && (body = getBodyTextAsJSON()) != null) {
        try {
            Iterator keys = body.keys();
            Log.d(LOG_TAG, "JSON data:");
            while (keys.hasNext()) {
                String key = (String) keys.next();
                Log.d(LOG_TAG, "  " + key + ": " + body.get(key));
                params.put(key, body.get(key).toString());
            }
        } catch (JSONException e) {
            Log.w(LOG_TAG, "Unable to retrieve a JSON value", e);
        }
    }
    return client.post(this, URL, headers, params,
            RequestParams.APPLICATION_JSON, responseHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:22,代码来源:JsonStreamerSample.java

示例2: getTx

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的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

示例3: executeSample

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) {

    final Activity ctx = this;
    FutureTask<RequestHandle> future = new FutureTask<>(new Callable<RequestHandle>() {
        public RequestHandle call() {
            Log.d(LOG_TAG, "Executing GET request on background thread");
            return client.get(ctx, URL, headers, null, responseHandler);
        }
    });

    executor.execute(future);

    RequestHandle handle = null;
    try {
        handle = future.get(5, TimeUnit.SECONDS);
        Log.d(LOG_TAG, "Background thread for GET request has finished");
    } catch (Exception e) {
        Toast.makeText(ctx, e.getMessage(), Toast.LENGTH_LONG).show();
        e.printStackTrace();
    }

    return handle;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:AsyncBackgroundThreadSample.java

示例4: getBlockHash

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的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

示例5: executeSample

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
    RequestParams rParams = new RequestParams();
    rParams.put("sample_key", "Sample String");
    try {
        File sample_file = File.createTempFile("temp_", "_handled", getCacheDir());
        rParams.put("sample_file", sample_file);
    } catch (IOException e) {
        Log.e(LOG_TAG, "Cannot add sample file", e);
    }
    return client.post(this, URL, headers, rParams, "multipart/form-data", responseHandler);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:ContentTypeForHttpEntitySample.java

示例6: getResponseData

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
protected byte[] getResponseData(HttpEntity entity) throws IOException {
    if (entity != null) {
        InputStream instream = entity.getContent();
        long contentLength = entity.getContentLength();
        FileOutputStream buffer = new FileOutputStream(getTargetFile(), this.append);
        if (instream != null) {
            try {
                byte[] tmp = new byte[BUFFER_SIZE];
                int l, count = 0;
                // do not send messages if request has been cancelled
                while ((l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
                    count += l;
                    buffer.write(tmp, 0, l);
                    sendProgressMessage(count, contentLength);
                }
            } finally {
                AsyncHttpClient.silentCloseInputStream(instream);
                buffer.flush();
                AsyncHttpClient.silentCloseOutputStream(buffer);
            }
        }
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:26,代码来源:FileAsyncHttpResponseHandler.java

示例7: paramsToEntity

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
/**
 * Returns HttpEntity containing data from RequestParams included with request declaration.
 * Allows also passing progress from upload via provided ResponseHandler
 *
 * @param params          additional request params
 * @param responseHandler ResponseHandlerInterface or its subclass to be notified on progress
 */
private HttpEntity paramsToEntity(RequestParams params, ResponseHandlerInterface responseHandler) {
    HttpEntity entity = null;

    try {
        if (params != null) {
            entity = params.getEntity(responseHandler);
        }
    } catch (IOException e) {
        if (responseHandler != null) {
            responseHandler.sendFailureMessage(0, null, null, e);
        } else {
            e.printStackTrace();
        }
    }

    return entity;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:AsyncHttpClient.java

示例8: get

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的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

示例9: getResponseData

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
protected byte[] getResponseData(HttpEntity entity) throws IOException {
    if (entity != null) {
        InputStream instream = entity.getContent();
        long contentLength = entity.getContentLength() + current;
        FileOutputStream buffer = new FileOutputStream(getTargetFile(), append);
        if (instream != null) {
            try {
                byte[] tmp = new byte[BUFFER_SIZE];
                int l;
                while (current < contentLength && (l = instream.read(tmp)) != -1 && !Thread.currentThread().isInterrupted()) {
                    current += l;
                    buffer.write(tmp, 0, l);
                    sendProgressMessage(current, contentLength);
                }
            } finally {
                instream.close();
                buffer.flush();
                buffer.close();
            }
        }
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:RangeFileAsyncHttpResponseHandler.java

示例10: getBlock

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的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

示例11: executeSample

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
public RequestHandle executeSample(final AsyncHttpClient client, final String URL, final Header[] headers, HttpEntity entity, final ResponseHandlerInterface responseHandler) {
    if (client instanceof SyncHttpClient) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                Log.d(LOG_TAG, "Before Request");
                client.get(SynchronousClientSample.this, URL, headers, null, responseHandler);
                Log.d(LOG_TAG, "After Request");
            }
        }).start();
    } else {
        Log.e(LOG_TAG, "Error, not using SyncHttpClient");
    }
    /*
     * SyncHttpClient does not return RequestHandle,
     * it executes each request directly,
     * therefore those requests are not in cancelable threads
     * */
    return null;
}
 
开发者ID:Vorlonsoft,项目名称:AndroidAsyncHTTP,代码行数:22,代码来源:SynchronousClientSample.java

示例12: executeSample

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
    try {
        RequestParams params = new RequestParams();
        final String contentType = RequestParams.APPLICATION_OCTET_STREAM;
        params.put("fileOne", createTempFile("fileOne", 1020), contentType, "fileOne");
        params.put("fileTwo", createTempFile("fileTwo", 1030), contentType);
        params.put("fileThree", createTempFile("fileThree", 1040), contentType, "customFileThree");
        params.put("fileFour", createTempFile("fileFour", 1050), contentType);
        params.put("fileFive", createTempFile("fileFive", 1060), contentType, "testingFileFive");
        params.setHttpEntityIsRepeatable(true);
        params.setUseJsonStreamer(false);
        return client.post(this, URL, params, responseHandler);
    } catch (FileNotFoundException fnfException) {
        Log.e(LOG_TAG, "executeSample failed with FileNotFoundException", fnfException);
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:FilesSample.java

示例13: endEntityViaReflection

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
/**
 * This horrible hack is required on Android, due to implementation of BasicManagedEntity, which
 * doesn't chain call consumeContent on underlying wrapped HttpEntity
 *
 * @param entity HttpEntity, may be null
 */
public static void endEntityViaReflection(HttpEntity entity) {
    if (entity instanceof HttpEntityWrapper) {
        try {
            Field f = null;
            Field[] fields = HttpEntityWrapper.class.getDeclaredFields();
            for (Field ff : fields) {
                if (ff.getName().equals("wrappedEntity")) {
                    f = ff;
                    break;
                }
            }
            if (f != null) {
                f.setAccessible(true);
                HttpEntity wrapped = (HttpEntity) f.get(entity);
                if (wrapped != null) {
                    wrapped.consumeContent();
                }
            }
        } catch (Throwable t) {
            log.e(LOG_TAG, "wrappedEntity consume", t);
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:30,代码来源:AsyncHttpClient.java

示例14: executeSample

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
@Override
public RequestHandle executeSample(AsyncHttpClient client, String URL, Header[] headers, HttpEntity entity, ResponseHandlerInterface responseHandler) {
    Intent serviceCall = new Intent(this, ExampleIntentService.class);
    serviceCall.putExtra(ExampleIntentService.INTENT_URL, URL);
    startService(serviceCall);
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:IntentServiceSample.java

示例15: getRequestEntity

import cz.msebera.android.httpclient.HttpEntity; //导入依赖的package包/类
public HttpEntity getRequestEntity() {
    String bodyText;
    if (isRequestBodyAllowed() && (bodyText = getBodyText()) != null) {
        try {
            return new StringEntity(bodyText);
        } catch (UnsupportedEncodingException e) {
            Log.e(LOG_TAG, "cannot create String entity", e);
        }
    }
    return null;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:12,代码来源:SampleParentActivity.java


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