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


Java HttpEntity.setContentType方法代码示例

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


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

示例1: getTextPost

import org.apache.http.HttpEntity; //导入方法依赖的package包/类
private HttpPost getTextPost(String str, ArrayList<KVPair<String>> arrayList) throws Throwable {
    HttpPost httpPost = new HttpPost(str);
    if (arrayList != null) {
        StringPart stringPart = new StringPart();
        stringPart.append(kvPairsToUrl(arrayList));
        HttpEntity inputStreamEntity = stringPart.getInputStreamEntity();
        inputStreamEntity.setContentType(Client.FormMime);
        httpPost.setEntity(inputStreamEntity);
    }
    return httpPost;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:12,代码来源:NetworkHelper.java

示例2: jsonPost

import org.apache.http.HttpEntity; //导入方法依赖的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


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