本文整理匯總了Java中org.apache.commons.httpclient.methods.PostMethod.addParameters方法的典型用法代碼示例。如果您正苦於以下問題:Java PostMethod.addParameters方法的具體用法?Java PostMethod.addParameters怎麽用?Java PostMethod.addParameters使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.httpclient.methods.PostMethod
的用法示例。
在下文中一共展示了PostMethod.addParameters方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: httpClientPost
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public static final String httpClientPost(String url, ArrayList<NameValuePair> list) {
String result = "";
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(url);
try {
NameValuePair[] params = new NameValuePair[list.size()];
for (int i = 0; i < list.size(); i++) {
params[i] = list.get(i);
}
postMethod.addParameters(params);
client.executeMethod(postMethod);
result = postMethod.getResponseBodyAsString();
} catch (Exception e) {
logger.error("", e);
} finally {
postMethod.releaseConnection();
}
return result;
}
示例2: httpClientPost
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
public static final String httpClientPost(String url, ArrayList<NameValuePair> list) {
String result = "";
HttpClient client = new HttpClient();
PostMethod postMethod = new PostMethod(url);
try {
NameValuePair[] params = new NameValuePair[list.size()];
for (int i = 0; i < list.size(); i++) {
params[i] = list.get(i);
}
postMethod.addParameters(params);
client.executeMethod(postMethod);
result = postMethod.getResponseBodyAsString();
} catch (Exception e) {
logger.error(e);
} finally {
postMethod.releaseConnection();
}
return result;
}
示例3: executeQuery
import org.apache.commons.httpclient.methods.PostMethod; //導入方法依賴的package包/類
private HttpMethod executeQuery(FederatedSearch sruSearch, String query, SRUSettings settings, int offset,
int perpage) throws IOException
{
HttpMethod httpMethod = null;
try
{
// URL includes the port (if any) we trust ...
URL url = new URL(settings.getUrl());
PostMethod postMethod = new PostMethod(url.toExternalForm());
NameValuePair[] nameValuePairs = populateNameValuePairs(query, settings, offset, perpage);
postMethod.addParameters(nameValuePairs);
httpMethod = postMethod;
}
catch( Exception e )
{
throw new RuntimeException(e);
}
HttpClient httpClient = new HttpClient();
httpClient.getHttpConnectionManager().getParams().setConnectionTimeout(sruSearch.getTimeout() * 1000);
httpClient.getHttpConnectionManager().getParams().setSoTimeout(sruSearch.getTimeout() * 1000);
// Prevent the default 3 tries - so once is enough ...?
httpClient.getHttpConnectionManager().getParams().setParameter(HttpMethodParams.RETRY_HANDLER,
new DefaultHttpMethodRetryHandler(0, false));
httpClient.executeMethod(httpMethod);
return httpMethod;
}