當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpMethodParams.setParameter方法代碼示例

本文整理匯總了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;
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:21,代碼來源:ForwarderServlet.java

示例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;
}
 
開發者ID:openNaEF,項目名稱:openNaEF,代碼行數:21,代碼來源:ForwarderServlet.java

示例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);
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:17,代碼來源:HttpClientUtils.java

示例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;
    }
 
開發者ID:nkasvosve,項目名稱:beyondj,代碼行數:34,代碼來源:ServiceDownloadUtil.java

示例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");
}
 
開發者ID:thunlp,項目名稱:THUTag,代碼行數:15,代碼來源:WebCrawler.java

示例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;
}
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:29,代碼來源:VocsUtils.java

示例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;
}
 
開發者ID:Ctrip-DI,項目名稱:Hue-Ctrip-DI,代碼行數:31,代碼來源:YarnJobCrawlerTask.java

示例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;
    }
 
開發者ID:hugomanguinhas,項目名稱:europeana,代碼行數:20,代碼來源:NegotiationValidator.java

示例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;
}
 
開發者ID:werelate,項目名稱:wikidata,代碼行數:44,代碼來源:StandardizePlaces.java


注:本文中的org.apache.commons.httpclient.params.HttpMethodParams.setParameter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。