GetMethod method = new GetMethod("example.com/page"); method.setQueryString(new NameValuePair[] { new NameValuePair("key", "value") });
nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue())); gm.setQueryString(nameValuePairs.toArray(new NameValuePair[0]));
nameValuePairs.add(new NameValuePair(e.getKey(), e.getValue())); getMethod.setQueryString(nameValuePairs.toArray(new NameValuePair[0]));
public void setQueryString(String queryString) { if (queryString != null) { super.setQueryString('?' + queryString); } else { super.setQueryString(queryString); } }
public void setQueryString(String queryString) { if (queryString != null) { super.setQueryString('?' + queryString); } else { super.setQueryString(queryString); } }
method.setQueryString(new NameValuePair[]{ }); } else { method.setQueryString(nvPairArray); // Encoding is taken care of here by setQueryString
@Override public String getOpenMrsAtomFeedSinceDate(String lastUpdateTime) { GetMethod get = new GetMethod(openmrsPath + ATOM_FEED_MODULE_PATH); NameValuePair[] params = new NameValuePair[1]; params[0] = new NameValuePair("asOfDate", lastUpdateTime); get.setQueryString(params); return executeGetMethod(get); } }
GetMethod getGETMethod(String servicePath, List<WebscriptParam> params) { GetMethod getMethod = new GetMethod(this.baseUrl + servicePath); if (params != null) { List<NameValuePair> args = new ArrayList<NameValuePair>(); for (WebscriptParam param : params) { args.add(new NameValuePair(param.getName(), param.getValue())); } getMethod.setQueryString(args.toArray(new NameValuePair[args.size()])); } return getMethod; }
/************************************************************************/ public static String loadWebPage(String url, String parameters) { try { HttpClient client = new HttpClient(); GetMethod method = new GetMethod(url); method.setQueryString(parameters); client.executeMethod(method); String html = method.getResponseBodyAsString(); return html; } catch (Exception e) { throw ObjectUtils.throwAsError(e); } } }
public Set<String> loggerPatterns() throws IOException { final GetMethod method = new GetMethod(getUrl()); method.setQueryString(new NameValuePair[]{new NameValuePair("o", "loggersConfig")}); final String content = executeAndGetContent(method); final Type type = new TypeToken<Collection<LoggerPatternsResponse>>() { }.getType(); final List<LoggerPatternsResponse> o = new Gson().fromJson(content, type); return o.stream().flatMap(patterns -> patterns.getPatterns().stream()).collect(Collectors.toSet()); }
/** * 发送POST请求 * @param uParamsMap Map形式的参数 * @param getUrl GET请求的URL * @param expireSeconds 请求超时时间,单位为秒 * @param charSet 字符集 */ public static String getHttpRequest(Map<String, String> uParamsMap, String getUrl, int expireSeconds, String charSet) { //logger.info("以HTTP Client的方式,发送GET请求."); NameValuePair[] nameValuPairArray = convertParamsMap2NameValuePair(uParamsMap); GetMethod getMethod = new GetMethod(getUrl); if (charSet == null) { getMethod.setQueryString(nameValuPairArray); } else { String queryString = EncodingUtil.formUrlEncode(nameValuPairArray, charSet); getMethod.setQueryString(queryString); } String result = httpRequest(getMethod, expireSeconds, getUrl, charSet); //logger.info("GET请求发送完毕. "); return result; }
/** * Method to execute a GET request to the given URL with the given parameters. * @param url * @param parameters * @return */ private String doGet(String url, Map<String, String[]> parameters, String mimeType) throws IOException, CatalogException { // build HTTP/GET request GetMethod method = new GetMethod(url); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (Map.Entry<String, String[]> key : parameters.entrySet()) { for (String value : key.getValue()) { nvps.add(new NameValuePair(key.getKey(), value)); } } // request results in JSON format if (mimeType.equals(Parameters.MIME_TYPE_JSON)) { nvps.add(new NameValuePair("wt", "json")); } method.setQueryString( nvps.toArray( new NameValuePair[nvps.size()] ) ); LOG.info("GET url: "+url+" query string: "+method.getQueryString()); // send HTTP/GET request, return response return doHttp(method); }
private HttpMethod generateRequestFor(String voxeoUrl, String tokenId, String externalId, CallRequest callRequest) { GetMethod getMethod = new GetMethod(voxeoUrl); List<NameValuePair> queryStringValues = new ArrayList<NameValuePair>(); queryStringValues.add(new NameValuePair("tokenid", tokenId)); queryStringValues.add(new NameValuePair("externalId", externalId)); queryStringValues.add(new NameValuePair("phonenum", callRequest.getPhone())); queryStringValues.add(new NameValuePair("vxml", callRequest.getCallBackUrl())); List<String> additionalParameters = Arrays.asList(MOTECH_ID, CALLER_ID); for (Entry<String, String> param : callRequest.getPayload().entrySet()) { if (additionalParameters.contains(param.getKey())) { queryStringValues.add(new NameValuePair(param.getKey(), param.getValue())); } } int callTimeOut = callRequest.getTimeOut(); if (0 != callTimeOut) { queryStringValues.add(new NameValuePair("timeout", Integer.toString(callTimeOut) + "s")); } getMethod.setQueryString(queryStringValues.toArray(new NameValuePair[queryStringValues.size()])); return getMethod; } }
/** * Performs the service request "CloseSession". * * @exception ClientException * if something went wrong during the request * @exception org.n52.security.common.protocol.artifact.ServiceException * if the response is of MIME type <code>application/vnd.ogc.se_xml */ public void closeSession(String version, String sessionID) throws ClientException, ServiceException { GetMethod getMethod = new GetMethod(getWssURLString()); NameValuePair[] kvps = new NameValuePair[] {new NameValuePair("VERSION", version), new NameValuePair("REQUEST", "CloseSession"), new NameValuePair("SESSIONID", sessionID)}; getMethod.setQueryString(kvps); // getMethod.setParameter("VERSION", version); // getMethod.setParameter("REQUEST", "CloseSession"); // getMethod.setParameter("SESSIONID", sessionID); try { client.executeMethod(getMethod); } catch (IOException ioe) { sLogger.error("", ioe); throw new ClientException("I/O exception during CLOSESESSION request to Security Service:\n" + ioe.getMessage()); } finally { getMethod.releaseConnection(); } }
/** Simple means to return the search result as an InputStream */ public java.io.InputStream searchAsInputStream(DiscoverQuery query) throws SearchServiceException, java.io.IOException { try { org.apache.commons.httpclient.methods.GetMethod method = new org.apache.commons.httpclient.methods.GetMethod(getSolr().getHttpClient().getHostConfiguration().getHostURL() + ""); method.setQueryString(query.toString()); getSolr().getHttpClient().executeMethod(method); return method.getResponseBodyAsStream(); } catch (org.apache.solr.client.solrj.SolrServerException e) { throw new SearchServiceException(e.getMessage(), e); } }
HttpClient client = new HttpClient(); NameValuePair arg1 = new NameValuePair("method","runJob"); //Change your currency types here in which you would want to convert NameValuePair arg2 = new NameValuePair("from","USD"); NameValuePair arg3 = new NameValuePair("to", "PKR"); //getting the method GetMethod method = new GetMethod("http://rate-exchange.appspot.com/currency"); method.setQueryString(new NameValuePair[]{arg1, arg2, arg3}); //executes the link client.executeMethod(method); //getting response in string JSONObject obj = new JSONObject(method.getResponseBodyAsString()); //getting rate from the json response double rate = obj.getDouble("rate"); //closing conncetion method.releaseConnection(); //returning value return rate;
HttpClient client = new HttpClient(); NameValuePair arg1 = new NameValuePair("method","runJob"); //Change your currency types here in which you would want to convert NameValuePair arg2 = new NameValuePair("from","USD"); NameValuePair arg3 = new NameValuePair("to", "PKR"); //getting the method GetMethod method = new GetMethod("http://rate-exchange.appspot.com/currency"); method.setQueryString(new NameValuePair[]{arg1, arg2, arg3}); //executes the link client.executeMethod(method); //getting response in string JSONObject obj = new JSONObject(method.getResponseBodyAsString()); //getting rate from the json response double rate = obj.getDouble("rate"); //closing conncetion method.releaseConnection(); //returning value return rate;
public static String accessResource_Appache_commons(String url){ String response_String = null; HttpClient client = new HttpClient(); GetMethod method = new GetMethod( url ); // PostMethod method = new PostMethod( url ); method.setRequestHeader("Content-type", "text/xml; charset=ISO-8859-1"); method.setQueryString(new NameValuePair[] { new NameValuePair("param1","value1"), new NameValuePair("param2","value2") }); //The pairs are encoded as UTF-8 characters. try{ int statusCode = client.executeMethod(method); System.out.println("Status Code = "+statusCode); //Get data as a String OR BYTE array method.getResponseBody() response_String = method.getResponseBodyAsString(); method.releaseConnection(); } catch(IOException e) { e.printStackTrace(); } return response_String; }
getMethod.setQueryString(queryParams.toArray(new NameValuePair[queryParams.size()]));
@Override public GeoLocation getCurrentGeoLocation() throws Exception { HttpClient httpClient = component.getHttpClient(); if (isEmpty(component.getGeolocationAccessKey())) { throw new IllegalStateException("The geolocation service requires a mandatory geolocationAccessKey"); } if (isEmpty(component.getGeolocationRequestHostIP())) { throw new IllegalStateException("The geolocation service requires a mandatory geolocationRequestHostIP"); } GetMethod getMethod = new GetMethod("http://api.ipstack.com/" + component.getGeolocationRequestHostIP()); getMethod.setQueryString(new NameValuePair[] {new NameValuePair("access_key", component.getGeolocationAccessKey()), new NameValuePair("legacy", "1"), new NameValuePair("output", "json")}); try { int statusCode = httpClient.executeMethod(getMethod); if (statusCode != HttpStatus.SC_OK) { throw new IllegalStateException("Got the unexpected http-status '" + getMethod.getStatusLine() + "' for the geolocation"); } String geoLocation = component.getCamelContext().getTypeConverter().mandatoryConvertTo(String.class, getMethod.getResponseBodyAsStream()); if (isEmpty(geoLocation)) { throw new IllegalStateException("Got the unexpected value '" + geoLocation + "' for the geolocation"); } ObjectMapper mapper = new ObjectMapper(); JsonNode node = mapper.readValue(geoLocation, JsonNode.class); JsonNode latitudeNode = notNull(node.get("latitude"), "latitude"); JsonNode longitudeNode = notNull(node.get("longitude"), "longitude"); return new GeoLocation(longitudeNode.asText(), latitudeNode.asText()); } finally { getMethod.releaseConnection(); } }