List of usage examples for org.apache.commons.httpclient NameValuePair getValue
public String getValue()
From source file:com.feilong.tools.net.httpclient3.NameValuePairUtil.java
/** * nameValuePairs?Map.//from w w w .j av a 2s . co m * * @param nameValuePairs * the name value pairs * @return if (Validator.isNotNullOrEmpty(nameValuePairs)), will return Collections.emptyMap() * @since 1.0.9 */ public static Map<String, String> toMap(NameValuePair[] nameValuePairs) { if (Validator.isNotNullOrEmpty(nameValuePairs)) { Map<String, String> map = new TreeMap<String, String>(); for (NameValuePair nameValuePair : nameValuePairs) { map.put(nameValuePair.getName(), nameValuePair.getValue()); } return map; } return Collections.emptyMap(); }
From source file:de.laeubisoft.tools.ant.validation.Tools.java
public static List<Part> nvToParts(List<NameValuePair> params) { List<Part> parts = new ArrayList<Part>(); for (NameValuePair nameValuePair : params) { parts.add(new StringPart(nameValuePair.getName(), nameValuePair.getValue())); }//from w w w .ja v a 2 s .c o m return parts; }
From source file:com.cloudbees.workflow.Util.java
public static int postToJenkins(Jenkins jenkins, String url, String content, String contentType) throws IOException { String jenkinsUrl = jenkins.getRootUrl(); URL urlObj = new URL(jenkinsUrl + url.replace("/jenkins/job/", "job/")); HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection(); try {//w w w . j av a2 s . c o m conn.setRequestMethod("POST"); // Set the crumb header, otherwise the POST may be rejected. NameValuePair crumbHeader = getCrumbHeaderNVP(jenkins); conn.setRequestProperty(crumbHeader.getName(), crumbHeader.getValue()); if (contentType != null) { conn.setRequestProperty("Content-Type", contentType); } if (content != null) { byte[] bytes = content.getBytes(Charset.forName("UTF-8")); conn.setDoOutput(true); conn.setRequestProperty("Content-Length", String.valueOf(bytes.length)); final OutputStream os = conn.getOutputStream(); try { os.write(bytes); os.flush(); } finally { os.close(); } } return conn.getResponseCode(); } finally { conn.disconnect(); } }
From source file:com.intellij.tasks.impl.httpclient.ResponseUtil.java
public static Reader getResponseContentAsReader(@Nonnull HttpMethod response) throws IOException { //if (!response.hasBeenUsed()) { // return new StringReader(""); //}/*from w w w . j a v a 2 s . c o m*/ InputStream stream = response.getResponseBodyAsStream(); String charsetName = null; org.apache.commons.httpclient.Header header = response.getResponseHeader(HTTP.CONTENT_TYPE); if (header != null) { // find out encoding for (HeaderElement part : header.getElements()) { NameValuePair pair = part.getParameterByName("charset"); if (pair != null) { charsetName = pair.getValue(); } } } return new InputStreamReader(stream, charsetName == null ? DEFAULT_CHARSET_NAME : charsetName); }
From source file:brainleg.app.util.AppWeb.java
/** * Copied from ITNProxy//from w w w . ja v a 2 s. c o m * @param params * @return * @throws UnsupportedEncodingException */ private static byte[] join(List<NameValuePair> params) throws UnsupportedEncodingException { StringBuilder builder = new StringBuilder(); Iterator<NameValuePair> it = params.iterator(); while (it.hasNext()) { NameValuePair param = it.next(); if (StringUtil.isEmpty(param.getName())) throw new IllegalArgumentException(param.toString()); if (StringUtil.isNotEmpty(param.getValue())) builder.append(param.getName()).append("=").append(URLEncoder.encode(param.getValue(), ENCODING)); if (it.hasNext()) builder.append(POST_DELIMITER); } return builder.toString().getBytes(); }
From source file:flex.messaging.services.http.httpclient.FlexGetMethod.java
protected String getContentCharSet(Header contentheader) { String charset = null;/*w ww .j av a 2 s .co m*/ if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset == null) { charset = "UTF-8"; } return charset; }
From source file:net.sf.antcontrib.net.httpclient.PostMethodTask.java
public void addConfiguredParameter(NameValuePair pair) { getPostMethod().setParameter(pair.getName(), pair.getValue()); }
From source file:jshm.sh.client.HttpForm.java
public final void submit() throws Exception { LOG.fine("Submitting form via " + methodName + " to " + url); for (NameValuePair nvp : data) { LOG.finer(" " + nvp.getName() + "=" + (nvp.getName().toLowerCase().contains("pass") ? "*****" : nvp.getValue())); }/*w w w. j a va 2s . c o m*/ LOG.finest("calling getHttpClient()"); HttpClient client = Client.getHttpClient(); LOG.finest("executing method"); int response = client.executeMethod(this.method); LOG.fine("Received " + response + " response code"); this.afterSubmit(response, client, this.method); LOG.finest("exiting HttpForm.submit()"); }
From source file:com.eviware.soapui.impl.wsdl.submit.transports.http.support.attachments.MimeMessageResponse.java
public MimeMessageResponse(AbstractHttpRequestInterface<?> httpRequest, ExtendedHttpMethod httpMethod, String requestContent, PropertyExpansionContext context) { super(httpMethod, httpRequest, context); if (getRequestContent() == null || !getRequestContent().equals(requestContent)) this.requestContent = requestContent; try {// ww w . j a v a 2s. c o m postResponseDataSource = new PostResponseDataSource(httpMethod); responseContentLength = postResponseDataSource.getDataSize(); Header h = httpMethod.getResponseHeader("Content-Type"); HeaderElement[] elements = h.getElements(); String rootPartId = null; for (HeaderElement element : elements) { String name = element.getName().toUpperCase(); if (name.startsWith("MULTIPART/")) { NameValuePair parameter = element.getParameterByName("start"); if (parameter != null) rootPartId = parameter.getValue(); } } mmSupport = new MultipartMessageSupport(postResponseDataSource, rootPartId, (AbstractHttpOperation) httpRequest.getOperation(), false, httpRequest.isPrettyPrint()); if (httpRequest.getSettings().getBoolean(HttpSettings.INCLUDE_RESPONSE_IN_TIME_TAKEN)) this.timeTaken += httpMethod.getResponseReadTime(); } catch (Exception e) { SoapUI.logError(e); } }
From source file:com.boyuanitsm.pay.alipay.util.httpClient.HttpProtocolHandler.java
/** * NameValuePairs?/*from w w w . ja va2s . c om*/ * * @param nameValues * @return */ protected String toString(NameValuePair[] nameValues) { if (nameValues == null || nameValues.length == 0) { return "null"; } StringBuffer buffer = new StringBuffer(); for (int i = 0; i < nameValues.length; i++) { NameValuePair nameValue = nameValues[i]; if (i == 0) { buffer.append(nameValue.getName() + "=" + nameValue.getValue()); } else { buffer.append("&" + nameValue.getName() + "=" + nameValue.getValue()); } } return buffer.toString(); }