本文整理汇总了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;
}
示例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));
}