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


Java HttpUriRequest.setEntity方法代码示例

本文整理汇总了Java中org.apache.http.client.methods.HttpUriRequest.setEntity方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUriRequest.setEntity方法的具体用法?Java HttpUriRequest.setEntity怎么用?Java HttpUriRequest.setEntity使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.methods.HttpUriRequest的用法示例。


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

示例1: rawPost

import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public void rawPost(String str, ArrayList<KVPair<String>> arrayList, HTTPPart hTTPPart,
                    HttpResponseCallback httpResponseCallback) throws Throwable {
    long currentTimeMillis = System.currentTimeMillis();
    Ln.i("raw post: " + str, new Object[0]);
    HttpUriRequest httpPost = new HttpPost(str);
    if (arrayList != null) {
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            KVPair kVPair = (KVPair) it.next();
            httpPost.setHeader(kVPair.name, (String) kVPair.value);
        }
    }
    httpPost.setEntity(hTTPPart.getInputStreamEntity());
    HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
            DefaultHttpClient();
    HttpResponse execute = sSLHttpClient.execute(httpPost);
    if (httpResponseCallback != null) {
        httpResponseCallback.onResponse(execute);
    }
    sSLHttpClient.getConnectionManager().shutdown();
    Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:NetworkHelper.java

示例2: c

import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
private HttpUriRequest c() {
    if (this.f != null) {
        return this.f;
    }
    if (this.j == null) {
        byte[] b = this.c.b();
        CharSequence b2 = this.c.b(AsyncHttpClient.ENCODING_GZIP);
        if (b != null) {
            if (TextUtils.equals(b2, "true")) {
                this.j = b.a(b);
            } else {
                this.j = new ByteArrayEntity(b);
            }
            this.j.setContentType(this.c.c());
        }
    }
    HttpEntity httpEntity = this.j;
    if (httpEntity != null) {
        HttpUriRequest httpPost = new HttpPost(b());
        httpPost.setEntity(httpEntity);
        this.f = httpPost;
    } else {
        this.f = new HttpGet(b());
    }
    return this.f;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:27,代码来源:q.java

示例3: upload

import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public static Statistic upload(Context context, String str, Bundle bundle) throws MalformedURLException, IOException, NetworkUnavailableException, HttpStatusException {
    int size;
    int i;
    byte[] byteArray;
    if (context != null) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService("connectivity");
        if (connectivityManager != null) {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
                throw new NetworkUnavailableException(NetworkUnavailableException.ERROR_INFO);
            }
        }
    }
    Bundle bundle2 = new Bundle(bundle);
    String str2 = "";
    str2 = bundle2.getString("appid_for_getting_config");
    bundle2.remove("appid_for_getting_config");
    HttpClient httpClient = HttpUtils.getHttpClient(context, str2, str);
    HttpUriRequest httpPost = new HttpPost(str);
    Bundle bundle3 = new Bundle();
    for (String str22 : bundle2.keySet()) {
        Object obj = bundle2.get(str22);
        if (obj instanceof byte[]) {
            bundle3.putByteArray(str22, (byte[]) obj);
        }
    }
    httpPost.setHeader(HttpRequest.HEADER_CONTENT_TYPE, "multipart/form-data; boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f");
    httpPost.setHeader("Connection", "Keep-Alive");
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byteArrayOutputStream.write(getBytesUTF8("--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
    byteArrayOutputStream.write(getBytesUTF8(encodePostBody(bundle2, "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f")));
    if (!bundle3.isEmpty()) {
        size = bundle3.size();
        byteArrayOutputStream.write(getBytesUTF8("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
        i = -1;
        for (String str222 : bundle3.keySet()) {
            i++;
            byteArrayOutputStream.write(getBytesUTF8("Content-Disposition: form-data; name=\"" + str222 + "\"; filename=\"" + "value.file" + "\"" + "\r\n"));
            byteArrayOutputStream.write(getBytesUTF8("Content-Type: application/octet-stream\r\n\r\n"));
            byteArray = bundle3.getByteArray(str222);
            if (byteArray != null) {
                byteArrayOutputStream.write(byteArray);
            }
            if (i < size - 1) {
                byteArrayOutputStream.write(getBytesUTF8("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
            }
        }
    }
    byteArrayOutputStream.write(getBytesUTF8("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f--\r\n"));
    byteArray = byteArrayOutputStream.toByteArray();
    i = byteArray.length + 0;
    byteArrayOutputStream.close();
    httpPost.setEntity(new ByteArrayEntity(byteArray));
    HttpResponse execute = httpClient.execute(httpPost);
    size = execute.getStatusLine().getStatusCode();
    if (size == 200) {
        return new Statistic(a(execute), i);
    }
    throw new HttpStatusException(HttpStatusException.ERROR_INFO + size);
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:61,代码来源:Util.java

示例4: jsonPost

import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public String jsonPost(String str, ArrayList<KVPair<String>> arrayList,
                       ArrayList<KVPair<String>> arrayList2, ArrayList<KVPair<?>> arrayList3)
        throws Throwable {
    long currentTimeMillis = System.currentTimeMillis();
    Ln.i("jsonPost: " + str, new Object[0]);
    HttpUriRequest httpPost = new HttpPost(str);
    StringPart stringPart = new StringPart();
    if (arrayList != null) {
        HashMap hashMap = new HashMap();
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            KVPair kVPair = (KVPair) it.next();
            hashMap.put(kVPair.name, kVPair.value);
        }
        stringPart.append(new Hashon().fromHashMap(hashMap));
    }
    HttpEntity inputStreamEntity = stringPart.getInputStreamEntity();
    inputStreamEntity.setContentType("application/json");
    httpPost.setEntity(inputStreamEntity);
    if (arrayList2 != null) {
        Iterator it2 = arrayList2.iterator();
        while (it2.hasNext()) {
            kVPair = (KVPair) it2.next();
            httpPost.setHeader(kVPair.name, (String) kVPair.value);
        }
    }
    HttpParams basicHttpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(basicHttpParams, connectionTimeout);
    HttpConnectionParams.setSoTimeout(basicHttpParams, readTimout);
    if (arrayList3 != null) {
        Iterator it3 = arrayList3.iterator();
        while (it3.hasNext()) {
            kVPair = (KVPair) it3.next();
            try {
                basicHttpParams.setIntParameter(kVPair.name, R.parseInt(String.valueOf(kVPair
                        .value)));
            } catch (Exception e) {
            }
        }
    }
    httpPost.setParams(basicHttpParams);
    HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
            DefaultHttpClient();
    HttpResponse execute = sSLHttpClient.execute(httpPost);
    int statusCode = execute.getStatusLine().getStatusCode();
    if (statusCode == 200 || statusCode == 201) {
        String entityUtils = EntityUtils.toString(execute.getEntity(), Constants.UTF_8);
        sSLHttpClient.getConnectionManager().shutdown();
        Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
        return entityUtils;
    }
    entityUtils = EntityUtils.toString(execute.getEntity(), Constants.UTF_8);
    HashMap hashMap2 = new HashMap();
    hashMap2.put("error", entityUtils);
    hashMap2.put("status", Integer.valueOf(statusCode));
    sSLHttpClient.getConnectionManager().shutdown();
    throw new Throwable(new Hashon().fromHashMap(hashMap2));
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:59,代码来源:NetworkHelper.java

示例5: upload

import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public static Statistic upload(Context context, String str, Bundle bundle) throws
        MalformedURLException, IOException, NetworkUnavailableException, HttpStatusException {
    int size;
    int i;
    byte[] byteArray;
    if (context != null) {
        ConnectivityManager connectivityManager = (ConnectivityManager) context
                .getSystemService("connectivity");
        if (connectivityManager != null) {
            NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
            if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
                throw new NetworkUnavailableException(NetworkUnavailableException.ERROR_INFO);
            }
        }
    }
    Bundle bundle2 = new Bundle(bundle);
    String str2 = "";
    str2 = bundle2.getString("appid_for_getting_config");
    bundle2.remove("appid_for_getting_config");
    HttpClient httpClient = HttpUtils.getHttpClient(context, str2, str);
    HttpUriRequest httpPost = new HttpPost(str);
    Bundle bundle3 = new Bundle();
    for (String str22 : bundle2.keySet()) {
        Object obj = bundle2.get(str22);
        if (obj instanceof byte[]) {
            bundle3.putByteArray(str22, (byte[]) obj);
        }
    }
    httpPost.setHeader("Content-Type", "multipart/form-data; " +
            "boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f");
    httpPost.setHeader("Connection", "Keep-Alive");
    ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
    byteArrayOutputStream.write(getBytesUTF8("--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
    byteArrayOutputStream.write(getBytesUTF8(encodePostBody(bundle2,
            "3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f")));
    if (!bundle3.isEmpty()) {
        size = bundle3.size();
        byteArrayOutputStream.write(getBytesUTF8
                ("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
        i = -1;
        for (String str222 : bundle3.keySet()) {
            i++;
            byteArrayOutputStream.write(getBytesUTF8("Content-Disposition: form-data; " +
                    "name=\"" + str222 + "\"; filename=\"" + "value.file" + a.e + "\r\n"));
            byteArrayOutputStream.write(getBytesUTF8("Content-Type: " +
                    "application/octet-stream\r\n\r\n"));
            byteArray = bundle3.getByteArray(str222);
            if (byteArray != null) {
                byteArrayOutputStream.write(byteArray);
            }
            if (i < size - 1) {
                byteArrayOutputStream.write(getBytesUTF8
                        ("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
            }
        }
    }
    byteArrayOutputStream.write(getBytesUTF8
            ("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f--\r\n"));
    byteArray = byteArrayOutputStream.toByteArray();
    i = byteArray.length + 0;
    byteArrayOutputStream.close();
    httpPost.setEntity(new ByteArrayEntity(byteArray));
    HttpResponse execute = httpClient.execute(httpPost);
    size = execute.getStatusLine().getStatusCode();
    if (size == 200) {
        return new Statistic(a(execute), i);
    }
    throw new HttpStatusException(HttpStatusException.ERROR_INFO + size);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:70,代码来源:Util.java


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