當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。