List of usage examples for org.apache.commons.httpclient NameValuePair NameValuePair
public NameValuePair(String name, String value)
From source file:es.gva.cit.catalog.csw.messages.CSWAbstractMessages.java
public static NameValuePair[] getHTTPGETCapabilities() { NameValuePair nvp1 = new NameValuePair("request", CSWConstants.OPERATION_GETCAPABILITIES); NameValuePair nvp2 = new NameValuePair("service", ServerData.SERVER_SUBTYPE_CATALOG_CSW); NameValuePair nvp3 = new NameValuePair("acceptFormats", "text/xml"); return new NameValuePair[] { nvp1, nvp2, nvp3 }; }
From source file:net.sourceforge.jwbf.actions.mw.login.PostLoginOld.java
/** * /*from ww w.jav a 2 s . c o m*/ * @param username * the * @param pw * password */ public PostLoginOld(final String username, final String pw, final String domain) { this.username = username; NameValuePair action = new NameValuePair("wpLoginattempt", "Log in"); NameValuePair url = new NameValuePair("wpRemember", "1"); NameValuePair userid = new NameValuePair("wpName", username); NameValuePair dom = new NameValuePair("wpDomain", domain); String pwLabel = "wpPassword"; NameValuePair password = new NameValuePair(pwLabel, pw); PostMethod pm = new PostMethod("/index.php?title=Special:Userlogin&action=submitlogin&type=login"); pm.getParams().setContentCharset(MediaWikiBot.CHARSET); pm.setRequestBody(new NameValuePair[] { action, url, userid, dom, password }); msgs.add(pm); }
From source file:net.praqma.jenkins.rqm.unit.TestSuiteExecutionRecordTests.java
@Test public void correctQueryString() { String suites = "mysuite1,mysuite2"; String myPlan = "myplan"; NameValuePair[] actual = TestSuiteExecutionRecord.getFilteringProperties(suites, myPlan); NameValuePair[] expected = { new NameValuePair("fields", "feed/entry/content/suiteexecutionrecord[title='mysuite1' or title='mysuite2']/*|testplan[title='myplan']") }; assertArrayEquals(expected, actual); String suiteEmpty = "mysuite1,"; NameValuePair[] actual2 = TestSuiteExecutionRecord.getFilteringProperties(suiteEmpty, myPlan); NameValuePair[] expected2 = { new NameValuePair("fields", "feed/entry/content/suiteexecutionrecord[title='mysuite1']/*|testplan[title='myplan']") }; assertArrayEquals(expected2, actual2); String suiteSingle = "mysuite1"; NameValuePair[] actual3 = TestSuiteExecutionRecord.getFilteringProperties(suiteSingle, myPlan); NameValuePair[] expected3 = { new NameValuePair("fields", "feed/entry/content/suiteexecutionrecord[title='mysuite1']/*|testplan[title='myplan']") }; assertArrayEquals(expected3, actual3); }
From source file:com.ironiacorp.http.impl.httpclient3.PostRequest.java
private void setParameters() { for (String name : job.getParameters().keySet()) { Object value = job.getParameter(name); NameValuePair pair = new NameValuePair(name, value.toString()); if (parameters.contains(pair)) { parameters.remove(pair);/*w w w . j av a2 s . com*/ } parameters.add(pair); } }
From source file:net.sourceforge.jwbf.actions.mw.util.PostModifyContent.java
/** * // w ww. j a v a 2s . c o m * @param a the * @param tab internal value set * @param login a */ public PostModifyContent(final ContentAccessable a, final Hashtable<String, String> tab, LoginData login) { String uS = ""; try { uS = "/index.php?title=" + URLEncoder.encode(a.getLabel(), MediaWikiBot.CHARSET) + "&action=submit"; } catch (UnsupportedEncodingException e) { e.printStackTrace(); } NameValuePair action = new NameValuePair("wpSave", "Save"); NameValuePair wpStarttime = new NameValuePair("wpStarttime", tab.get("wpStarttime")); NameValuePair wpEditToken = new NameValuePair("wpEditToken", tab.get("wpEditToken")); NameValuePair wpEdittime = new NameValuePair("wpEdittime", tab.get("wpEdittime")); NameValuePair wpTextbox = new NameValuePair("wpTextbox1", a.getText()); String editSummaryText = a.getEditSummary(); if (editSummaryText != null && editSummaryText.length() > 200) { editSummaryText = editSummaryText.substring(0, 200); } NameValuePair wpSummary = new NameValuePair("wpSummary", editSummaryText); NameValuePair wpMinoredit = new NameValuePair(); if (a.isMinorEdit()) { wpMinoredit.setValue("1"); wpMinoredit.setName("wpMinoredit"); } LOG.info("WRITE: " + a.getLabel()); PostMethod pm = new PostMethod(uS); pm.getParams().setContentCharset(MediaWikiBot.CHARSET); pm.setRequestBody(new NameValuePair[] { action, wpStarttime, wpEditToken, wpEdittime, wpTextbox, wpSummary, wpMinoredit }); msgs.add(pm); }
From source file:mesquite.tol.lib.BaseHttpRequestMaker.java
public static boolean contactServer(String s, String URI, StringBuffer response) { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(URI); NameValuePair[] pairs = new NameValuePair[1]; pairs[0] = new NameValuePair("build", StringEscapeUtils.escapeHtml("\t" + s + "\tOS =\t" + System.getProperty("os.name") + "\t" + System.getProperty("os.version") + "\tjava =\t" + System.getProperty("java.version") + "\t" + System.getProperty("java.vendor"))); method.setQueryString(pairs);//from w w w . java 2 s . com method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(3, false)); return executeMethod(client, method, response); }
From source file:com.zb.app.biz.service.WeixinTest.java
public void login() { httpClient = new HttpClient(); PostMethod post = new PostMethod(loginUrl); post.addParameter(new NameValuePair("username", account)); post.addParameter(new NameValuePair("pwd", DigestUtils.md5Hex(password))); post.addParameter(new NameValuePair("imgcode", "")); post.addParameter(new NameValuePair("f", "json")); post.setRequestHeader("Host", "mp.weixin.qq.com"); post.setRequestHeader("Referer", "https://mp.weixin.qq.com/cgi-bin/loginpage?t=wxm2-login&lang=zh_CN"); try {/* ww w . j a v a 2 s.c om*/ int code = httpClient.executeMethod(post); if (HttpStatus.SC_OK == code) { String res = post.getResponseBodyAsString(); JSONParser parser = new JSONParser(); JSONObject obj = (JSONObject) parser.parse(res); JSONObject _obj = (JSONObject) obj.get("base_resp"); @SuppressWarnings("unused") String msg = (String) _obj.get("err_msg"); String redirect_url = (String) obj.get("redirect_url"); Long errCode = (Long) _obj.get("ret"); if (0 == errCode) { isLogin = true; token = StringUtils.substringAfter(redirect_url, "token="); if (null == token) { token = StringUtils.substringBetween(redirect_url, "token=", "&"); } StringBuffer cookie = new StringBuffer(); for (Cookie c : httpClient.getState().getCookies()) { cookie.append(c.getName()).append("=").append(c.getValue()).append(";"); } this.cookiestr = cookie.toString(); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:edu.northwestern.bioinformatics.studycalendar.security.plugin.cas.direct.DirectLoginHttpFacade.java
/** * Contacts the CAS server and GETs its login form, returning the content as a string. *//*from www. ja v a2 s . c o m*/ public String getForm() throws IOException { log.trace("GETting {} to obtain login ticket", loginUrl); GetMethod get = initMethod(new GetMethod(loginUrl)); get.setQueryString(new NameValuePair[] { new NameValuePair("service", getServiceUrl()) }); try { httpClient.executeMethod(get); if (get.getStatusCode() == HttpStatus.SC_OK) { return get.getResponseBodyAsString(); } else { throw new CasDirectException("Retrieving the login form %s failed: %s", loginUrl, get.getStatusLine()); } } finally { get.releaseConnection(); } }
From source file:com.pureinfo.force.net.impl.HttpUtilImplTest.java
public void testGetContentWithArgs() throws IOTransferException { if (logger.isDebugEnabled()) { logger.debug("testGetContentWithArgs() - start"); logger.debug("HTML"); }/*from ww w . ja va2s . com*/ NameValuePair[] args = new NameValuePair[] { new NameValuePair("Email", "Freemanhu"), new NameValuePair("Passwd", "huxiaowen"), new NameValuePair("PersistentCookie", "no") }; String content = m_util.getContent("https://www.google.com/accounts/LoginAuth", args, "utf-8"); System.out.println(content); if (logger.isDebugEnabled()) { logger.debug("testGetContentWithArgs() - end"); } }
From source file:eu.learnpad.rest.utils.internal.DefaultCPRestUtils.java
public InputStream getModel(String modelId, String type) { HttpClient httpClient = getClient(); String uri = REST_URI + "/learnpad/model/" + modelId; GetMethod getMethod = new GetMethod(uri); NameValuePair[] queryString = new NameValuePair[1]; queryString[0] = new NameValuePair("type", type); getMethod.setQueryString(queryString); getMethod.addRequestHeader("Accept", "application/xml"); getMethod.addRequestHeader("Accept-Ranges", "bytes"); try {/*from www . j a v a2s. com*/ httpClient.executeMethod(getMethod); } catch (HttpException e) { logger.error("Unable to process the GET request for model '" + modelId + "' (" + type + ").", e); return null; } catch (IOException e) { logger.error("Unable to GET the '" + modelId + "' model (" + type + ").", e); return null; } try { return getMethod.getResponseBodyAsStream(); } catch (IOException e) { logger.error("Unable to extract the '" + modelId + "' model (" + type + ") from GET response.", e); return null; } }