List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters, final Charset charset)
From source file:LogToFile.java
private static HttpPost Post(String url, HashMap<String, String> params, HashMap<String, ArrayList<String>> arrayParams) { try {/* w w w .ja v a 2s . co m*/ if (!url.endsWith("/")) url += "/"; List<NameValuePair> params_list = null; if (params != null) { params_list = new LinkedList<NameValuePair>(); for (Entry<String, String> entry : params.entrySet()) params_list.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } if (arrayParams != null) { if (params_list == null) params_list = new LinkedList<NameValuePair>(); for (Entry<String, ArrayList<String>> entry : arrayParams.entrySet()) for (String value : entry.getValue()) params_list.add(new BasicNameValuePair(entry.getKey(), value)); } HttpPost request = new HttpPost(url); if (params != null) request.setEntity(new UrlEncodedFormEntity(params_list, "utf-8")); return request; } catch (Exception e) { Log.e("", e.getClass().getName() + "\n" + e.getMessage()); } return null; }
From source file:com.dss886.nForumSDK.http.PostMethod.java
public PostMethod(DefaultHttpClient httpClient, String auth, String url, ParamOption params) { this.httpClient = httpClient; httpPost = new HttpPost(url); try {//from w w w . j a v a 2s . c om httpPost.setEntity(new UrlEncodedFormEntity(params.toNamePair(), "UTF-8")); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } httpPost.setHeader("Accept-Encoding", "gzip, deflate"); httpPost.setHeader("Authorization", "Basic " + auth); }
From source file:nz.co.jsrsolutions.tideservice.scraper.provider.EasyTideAreaSelectClickHttpPost.java
public EasyTideAreaSelectClickHttpPost(URI uri, String viewState, String eventValidation, String areaId) { super(uri, viewState); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("__VIEWSTATE", viewState)); nvps.add(new BasicNameValuePair("__EVENTVALIDATION", eventValidation)); nvps.add(new BasicNameValuePair("__EVENTTARGET", "PortSelectionAreas$ddlAreas")); nvps.add(new BasicNameValuePair("__EVENTARGUMENT", "")); nvps.add(new BasicNameValuePair("__LASTFOCUS", "")); nvps.add(new BasicNameValuePair("PortSelectionAreas:ddlAreas", areaId)); setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); }
From source file:net.bither.api.GetCookieApi.java
@Override public HttpEntity getHttpEntity() throws Exception { long time = System.currentTimeMillis(); time = time / 1000 * 1000 + 215;// www . jav a 2 s. c o m List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(TIME_STRING, Long.toString(time))); return new UrlEncodedFormEntity(params, HTTP.UTF_8); }
From source file:nz.co.jsrsolutions.tideservice.scraper.provider.EasyTidePageLinkClickHttpPost.java
public EasyTidePageLinkClickHttpPost(URI uri, String viewState, String eventValidation, String areaId, String region, String controlId) { super(uri, viewState); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("__VIEWSTATE", viewState)); nvps.add(new BasicNameValuePair("__EVENTVALIDATION", eventValidation)); nvps.add(new BasicNameValuePair("__EVENTTARGET", controlId)); nvps.add(new BasicNameValuePair("__EVENTARGUMENT", "")); nvps.add(new BasicNameValuePair("__LASTFOCUS", "")); nvps.add(new BasicNameValuePair("PortSelectionAreas:ddlAreas", areaId)); nvps.add(new BasicNameValuePair("PortSelectionAreas:ddlRegions", region)); setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); }
From source file:nz.co.jsrsolutions.tideservice.scraper.provider.EasyTidePortLinkClickHttpPost.java
public EasyTidePortLinkClickHttpPost(URI uri, String viewState, String eventValidation, String areaId, String region, String controlId) { super(uri, viewState); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("__VIEWSTATE", viewState)); nvps.add(new BasicNameValuePair("__EVENTVALIDATION", eventValidation)); nvps.add(new BasicNameValuePair("__EVENTTARGET", controlId)); nvps.add(new BasicNameValuePair("__EVENTARGUMENT", "")); nvps.add(new BasicNameValuePair("__LASTFOCUS", "")); nvps.add(new BasicNameValuePair("PortSelectionAreas:ddlAreas", areaId)); nvps.add(new BasicNameValuePair("PortSelectionAreas:ddlRegions", region)); setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); }
From source file:org.fastcatsearch.util.HTMLTagRemoverTest.java
public void test1() { HttpClient httpclient = new DefaultHttpClient(); ResponseHandler<String> responseHandler = new BasicResponseHandler(); HttpPost httpost = new HttpPost("http://www.fastcatsearch.org/"); HttpGet httpGet = new HttpGet("http://www.fastcatsearch.org/"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); try {// www . j a v a2s . c o m httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); String responseBody = httpclient.execute(httpGet, responseHandler); System.out.println(HTMLTagRemover.clean(responseBody)); } catch (UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IRException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:org.dataconservancy.ui.it.support.SaveMetadataFormatRequest.java
public HttpPost asHttpPost() { final HttpPost form = new HttpPost(urlConfig.getUiConfigUrl().toExternalForm()); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair(STRIPES_EVENT, "submit")); UrlEncodedFormEntity entity = null;// ww w. j a v a 2 s.c o m try { entity = new UrlEncodedFormEntity(params, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } form.setEntity(entity); return form; }
From source file:com.currencyfair.minfraud.MinFraudImpl.java
@Override public RiskScoreResponse calculateRisk(RiskScoreRequest request) throws IOException { HttpPost req = methodFactory.createPost(endpoint.get()); List<NameValuePair> params = createParams(request); LOG.trace("Request parameters: {}", params); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, Consts.UTF_8); req.setEntity(entity);/*from w w w.j av a2s .c o m*/ HttpResponse resp = httpClient.execute(req); try (CloseableHttpResponseAdapter adapter = new CloseableHttpResponseAdapter(resp)) { int statusCode = resp.getStatusLine().getStatusCode(); if (statusCode == 200) { String responseValues = EntityUtils.toString(resp.getEntity(), Consts.ISO_8859_1); LOG.trace("minFraud response: {}", responseValues); RiskScoreResponse riskScore = RiskScoreResponse.extract(parseValueMap(responseValues)); riskScore.setRawResponse(responseValues); return riskScore; } else { throw new IOException("Unexpected response code from remote: " + statusCode); } } }
From source file:costumetrade.common.util.HttpClientUtils.java
/** * @param url// w ww. j a v a 2 s .c om * @param ? * @return */ public static String doPost(String url, Map<String, Object> params) { List<BasicNameValuePair> nvps = new ArrayList<>(params.size()); for (String key : params.keySet()) { Object value = params.get(key); if (value != null) { nvps.add(new BasicNameValuePair(key, value.toString())); } } return doPost(url, new UrlEncodedFormEntity(nvps, StandardCharsets.UTF_8)); }