use of org.apache.commons.httpclient.params.HttpClientParams in project dianping-open-sdk by dianping.
the class ApiTool method requestPostApi.
public static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
PostMethod method = new PostMethod(apiUrl);
try {
String sign = sign(appKey, secret, paramMap);
paramMap.put("sign", sign);
paramMap.put("appkey", appKey);
// 设置HTTP Post数据
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
method.addParameter(entry.getKey(), entry.getValue());
}
method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (IOException e) {
LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
use of org.apache.commons.httpclient.params.HttpClientParams in project dianping-open-sdk by dianping.
the class DemoApiTool method requestApi.
/**
* 请求API
*
* @param apiUrl
* @param appKey
* @param secret
* @param paramMap
* @return
*/
public static String requestApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
String queryString = getQueryString(appKey, secret, paramMap);
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
HttpMethod method = new GetMethod(apiUrl);
try {
if (queryString != null && !queryString.isEmpty()) {
// Encode query string with UTF-8
String encodeQuery = URIUtil.encodeQuery(queryString, "UTF-8");
method.setQueryString(encodeQuery);
}
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (URIException e) {
} catch (IOException e) {
} finally {
method.releaseConnection();
}
return response.toString();
}
use of org.apache.commons.httpclient.params.HttpClientParams in project dianping-open-sdk by dianping.
the class DemoApiTool method requestPostApi.
public static String requestPostApi(String apiUrl, String appKey, String secret, Map<String, String> paramMap) {
StringBuffer response = new StringBuffer();
HttpClientParams httpConnectionParams = new HttpClientParams();
httpConnectionParams.setConnectionManagerTimeout(1000);
HttpClient client = new HttpClient(httpConnectionParams);
PostMethod method = new PostMethod(apiUrl);
try {
String sign = sign(appKey, secret, paramMap);
paramMap.put("sign", sign);
paramMap.put("appkey", appKey);
// 设置HTTP Post数据
for (Map.Entry<String, String> entry : paramMap.entrySet()) {
method.addParameter(entry.getKey(), entry.getValue());
}
method.addRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8");
client.executeMethod(method);
BufferedReader reader = new BufferedReader(new InputStreamReader(method.getResponseBodyAsStream(), "UTF-8"));
String line = null;
while ((line = reader.readLine()) != null) {
response.append(line).append(System.getProperty("line.separator"));
}
reader.close();
} catch (IOException e) {
LOGGER.error("Request URL: " + apiUrl + " failed. ", e);
} finally {
method.releaseConnection();
}
return response.toString();
}
use of org.apache.commons.httpclient.params.HttpClientParams in project openhab1-addons by openhab.
the class CcuClient method start.
/**
* {@inheritDoc}
*/
@Override
public void start() throws HomematicClientException {
logger.info("Starting {}", CcuClient.class.getSimpleName());
super.start();
tclregaScripts = loadTclRegaScripts();
httpClient = new HttpClient(new SimpleHttpConnectionManager(true));
HttpClientParams params = httpClient.getParams();
Long timeout = context.getConfig().getTimeout() * 1000L;
params.setConnectionManagerTimeout(timeout);
params.setSoTimeout(timeout.intValue());
params.setContentCharset("ISO-8859-1");
}
use of org.apache.commons.httpclient.params.HttpClientParams in project zm-mailbox by Zimbra.
the class ZimbraHttpConnectionManager method createHttpClientParams.
private HttpClientParams createHttpClientParams() {
HttpClientParams clientParams = new HttpClientParams();
//
// Sets the timeout in milliseconds used when retrieving an HTTP connection from the HTTP connection manager.
//
// HttpClientParams.CONNECTION_MANAGER_TIMEOUT
//
clientParams.setConnectionManagerTimeout(getParams().getHttpClientConnectionTimeout());
return clientParams;
}
Aggregations