本文整理汇总了Java中org.apache.http.client.methods.HttpUriRequest.setParams方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUriRequest.setParams方法的具体用法?Java HttpUriRequest.setParams怎么用?Java HttpUriRequest.setParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.methods.HttpUriRequest
的用法示例。
在下文中一共展示了HttpUriRequest.setParams方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getHttpPostResponse
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public void getHttpPostResponse(String str, ArrayList<KVPair<String>> arrayList,
KVPair<String> kVPair, ArrayList<KVPair<String>> arrayList2,
ArrayList<KVPair<?>> arrayList3, HttpResponseCallback
httpResponseCallback) throws Throwable {
HttpUriRequest filePost;
long currentTimeMillis = System.currentTimeMillis();
Ln.i("httpPost: " + str, new Object[0]);
if (kVPair == null || kVPair.value == null || !new File((String) kVPair.value).exists()) {
Object textPost = getTextPost(str, arrayList);
} else {
ArrayList arrayList4 = new ArrayList();
arrayList4.add(kVPair);
filePost = getFilePost(str, arrayList, arrayList4);
}
if (arrayList2 != null) {
Iterator it = arrayList2.iterator();
while (it.hasNext()) {
KVPair kVPair2 = (KVPair) it.next();
filePost.setHeader(kVPair2.name, (String) kVPair2.value);
}
}
HttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicHttpParams, connectionTimeout);
HttpConnectionParams.setSoTimeout(basicHttpParams, readTimout);
if (arrayList3 != null) {
Iterator it2 = arrayList3.iterator();
while (it2.hasNext()) {
kVPair2 = (KVPair) it2.next();
try {
basicHttpParams.setIntParameter(kVPair2.name, R.parseInt(String.valueOf
(kVPair2.value)));
} catch (Exception e) {
}
}
}
filePost.setParams(basicHttpParams);
HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
DefaultHttpClient();
HttpResponse execute = sSLHttpClient.execute(filePost);
if (httpResponseCallback != null) {
httpResponseCallback.onResponse(execute);
}
sSLHttpClient.getConnectionManager().shutdown();
Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
}
示例2: httpPost
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public void httpPost(String str, ArrayList<KVPair<String>> arrayList,
ArrayList<KVPair<String>> arrayList2, ArrayList<KVPair<String>>
arrayList3, ArrayList<KVPair<?>> arrayList4,
HttpResponseCallback httpResponseCallback) throws Throwable {
HttpUriRequest filePost;
long currentTimeMillis = System.currentTimeMillis();
Ln.i("httpPost: " + str, new Object[0]);
if (arrayList2 == null || arrayList2.size() <= 0) {
Object textPost = getTextPost(str, arrayList);
} else {
filePost = getFilePost(str, arrayList, arrayList2);
}
if (arrayList3 != null) {
Iterator it = arrayList3.iterator();
while (it.hasNext()) {
KVPair kVPair = (KVPair) it.next();
filePost.setHeader(kVPair.name, (String) kVPair.value);
}
}
HttpParams basicHttpParams = new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(basicHttpParams, connectionTimeout);
HttpConnectionParams.setSoTimeout(basicHttpParams, readTimout);
Ln.i("before set SO_TIMEOUT :" + basicHttpParams.getIntParameter("http.socket.timeout",
readTimout), new Object[0]);
Ln.i("before set CONNECTION_TIMEOUT :" + basicHttpParams.getIntParameter("http.connection" +
".timeout", connectionTimeout), new Object[0]);
if (arrayList4 != null) {
Iterator it2 = arrayList4.iterator();
while (it2.hasNext()) {
kVPair = (KVPair) it2.next();
try {
basicHttpParams.setIntParameter(kVPair.name, R.parseInt(String.valueOf(kVPair
.value)));
} catch (Exception e) {
}
}
}
Ln.i("before set SO_TIMEOUT :" + basicHttpParams.getIntParameter("http.socket.timeout",
readTimout), new Object[0]);
Ln.i("before set CONNECTION_TIMEOUT :" + basicHttpParams.getIntParameter("http.connection" +
".timeout", connectionTimeout), new Object[0]);
filePost.setParams(basicHttpParams);
HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
DefaultHttpClient();
HttpResponse execute = sSLHttpClient.execute(filePost);
if (httpResponseCallback != null) {
try {
httpResponseCallback.onResponse(execute);
} catch (Throwable th) {
sSLHttpClient.getConnectionManager().shutdown();
}
}
sSLHttpClient.getConnectionManager().shutdown();
Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
}
示例3: 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));
}