本文整理汇总了Java中org.apache.commons.httpclient.params.HttpMethodParams.setParameter方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethodParams.setParameter方法的具体用法?Java HttpMethodParams.setParameter怎么用?Java HttpMethodParams.setParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.params.HttpMethodParams
的用法示例。
在下文中一共展示了HttpMethodParams.setParameter方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createGetMethod
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private HttpMethod createGetMethod(HttpServletRequest req, String uri) throws ServletException,
NotLoggedInException {
GetMethod get = new GetMethod(uri);
addUserNameToHeader(get, req);
addAcceptEncodingHeader(get, req);
get.getParams().setContentCharset("UTF-8");
HttpMethodParams params = new HttpMethodParams();
Enumeration e = req.getParameterNames();
while (e.hasMoreElements()) {
String paramName = (String) e.nextElement();
for (String value : req.getParameterValues(paramName)) {
params.setParameter(paramName, value);
}
}
get.setParams(params);
return get;
}
示例2: createDeleteMethod
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
private HttpMethod createDeleteMethod(HttpServletRequest req, String redirectUrl) throws IOException, ServletException, NotLoggedInException {
DeleteMethod delete = new DeleteMethod(redirectUrl);
addUserNameToHeader(delete, req);
addAcceptEncodingHeader(delete, req);
delete.getParams().setContentCharset("UTF-8");
HttpMethodParams params = new HttpMethodParams();
Enumeration e = req.getParameterNames();
while (e.hasMoreElements()) {
String paramName = (String) e.nextElement();
String[] values = req.getParameterValues(paramName);
for (String value : values) {
params.setParameter(paramName, value);
}
}
delete.setParams(params);
return delete;
}
示例3: get
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
/**
* 发送一个get请求
*
* @param url 地址
* @return
* @throws java.io.IOException
*/
public static String get(String url) throws IOException {
GetMethod method = new GetMethod(url);
HttpMethodParams hmp = method.getParams();
hmp.setParameter(HttpMethodParams.HTTP_CONTENT_CHARSET, DEFAULT_CHARSET);
hmp.setParameter(HttpMethodParams.SO_TIMEOUT, DEFAULT_TIMEOUT);
return executeMethod(method);
}
示例4: downloadMetricsRaw
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public static String downloadMetricsRaw(Config config, MetricsRequest metricsRequest) throws Exception {
Validate.notNull(config, "config must not be null");
Validate.notNull(metricsRequest, "metricsRequest must not be null");
String downloadUrl = config.getProperty(METRICS_PROVISION_URL);
HttpClient httpClient = new HttpClient();
HttpMethod method = new GetMethod(downloadUrl);
Marshaller marshaller = METRICS_REQ_JAXB_CONTEXT.createMarshaller();
StringWriter writer = new StringWriter();
marshaller.marshal(metricsRequest, writer);
HttpMethodParams params = new HttpMethodParams();
params.setParameter(METRICS_REQUEST, writer.toString());
int httpCode;
String response = null;
try {
httpCode = httpClient.executeMethod(method);
if (httpCode == 200) {
byte[] responseBody = method.getResponseBody();
response = new String(responseBody);
return response;
} else {
LOG.error(String.format("Download Failed for metrics from: %s, Response code is %d", downloadUrl, httpCode));
}
} catch (Exception e) {
LOG.error(String.format("Download Failed for metrics from: %s", downloadUrl), e);
} finally {
method.releaseConnection();
}
return null;
}
示例5: start
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public void start() {
LOG.log(Level.INFO, "inititalizing crawler");
// Initialize http client
httpClient = new HttpClient(new MultiThreadedHttpConnectionManager());
connParams = httpClient.getHttpConnectionManager().getParams();
connParams.setParameter(HttpConnectionParams.CONNECTION_TIMEOUT, this.connTimeout);
params = new HttpMethodParams();
params.setParameter(HttpMethodParams.USER_AGENT, this.agentString);
params.setParameter(HttpMethodParams.SO_TIMEOUT, this.getReadTimeout());
workers = new Hashtable<Integer, CrawlerThread>(this.maxConcurrency);
workersLock = new ReentrantReadWriteLock();
LOG.log(Level.INFO, "crawler started");
}
示例6: getRDF
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public static String getRDF(HttpClient client, String url)
{
try {
GetMethod method = new GetMethod(url);
method.setRequestHeader("Accept", "application/rdf+xml");
HttpMethodParams params = new HttpMethodParams();
params.setParameter(HttpMethodParams.RETRY_HANDLER, RETRY_HANDLER);
method.setParams(params);
int iRet = client.executeMethod(method);
if ( iRet != 200 ) {
System.err.println("problem fetching: <" + url + ">, response: " + iRet);
return null;
}
String s = method.getResponseBodyAsString();
System.err.println("fetched: <" + url + ">");
if ( RDF_PREPROCESSING ) {
s = s.replaceAll("rdf[:]datatype[=][\"]xsd[:]string[\"]", "");
}
return s;
} catch (Exception e) {
System.err.println("cannot fetch: <" + url + ">: reason <" + e.getClass().getName() + ">, msg: " + e.getMessage());
}
return null;
}
示例7: getJson
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
private JSONObject getJson() throws HttpException, IOException {
HttpClient httpClient = new HttpClient();
GetMethod method = new GetMethod(yarnHistoryJobUrl);
HttpMethodParams methodParams = new HttpMethodParams();
methodParams.setParameter("Content-Type", "application/json");
method.setParams(methodParams);
httpClient.executeMethod(method);
StringBuilder sb = new StringBuilder();
if (method.getStatusCode() == HttpStatus.SC_OK) {
BufferedReader reader = null;
try {
reader = new BufferedReader(new InputStreamReader(
method.getResponseBodyAsStream(), "UTF-8"));
String line;
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (Exception e) {
logger.error("Exception:", e);
throw new RuntimeException("Get json failed,", e);
} finally {
if (reader != null)
reader.close();
}
}
JSONObject jsonObject = JSONObject.fromObject(sb.toString());
return jsonObject;
}
示例8: newMethod
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
/**************************************************************************/
protected HttpMethodBase newMethod(String url, String accept)
{
HttpMethodBase method = newBaseMethod(_config.getMethod(), url);
if ( accept != null ) { method.setRequestHeader("Accept", accept); }
String agent = _config.getAgent();
if ( agent != null ) { method.setRequestHeader("User-Agent", agent); }
method.setFollowRedirects(false);
HttpMethodParams params = new HttpMethodParams();
params.setParameter(HttpMethodParams.RETRY_HANDLER, RETRY_HANDLER);
method.setParams(params);
return method;
}
示例9: getStandardizedPlaceNames
import org.apache.commons.httpclient.params.HttpMethodParams; //导入方法依赖的package包/类
public Map<String,String> getStandardizedPlaceNames(Set<String> names, PrintWriter err) throws IOException, SAXException, XPathExpressionException
{
Map<String,String> result = new HashMap<String,String>();
String query = Util.join("|", names);
String url = "http://"+placeServer+"/placestandardize";
PostMethod m = new PostMethod(url);
NameValuePair[] nvp = new NameValuePair[2];
nvp[0] = new NameValuePair("q", query);
nvp[1] = new NameValuePair("wt", "xml");
m.setRequestBody(nvp);
HttpMethodParams params = new HttpMethodParams();
params.setContentCharset("UTF-8");
params.setHttpElementCharset("UTF-8");
params.setParameter("http.protocol.content-charset", "UTF-8");
m.setParams(params);
m.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
int numTries = 0;
while (numTries++ < 3) {
try {
client.executeMethod(m);
break;
}
catch (IOException e) {
resetClient();
}
}
String response = m.getResponseBodyAsString();
Document doc = db.parse(new InputSource(new StringReader(response)));
NodeList lstNodes = (NodeList) lstExpression.evaluate(doc, XPathConstants.NODESET);
for (int i=0; i < lstNodes.getLength(); i++)
{
Node node = lstNodes.item(i);
String q = (String) queryExpression.evaluate(node, XPathConstants.STRING);
String placeTitle = (String)placeTitleExpression.evaluate(node, XPathConstants.STRING);
String error = (String) errorExpression.evaluate(node, XPathConstants.STRING);
if (err != null && !Util.isEmpty(error)) {
err.println(q);
}
placeTitle = getRedirTarget(placeTitle);
result.put(q,placeTitle);
}
return result;
}