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:jp.co.conit.sss.sp.ex1.util.SSSApiUtil.java
/** * ???/*from w w w . java 2 s.c om*/ * * @param signedData * @param signature * @return */ public static SPResult<List<VerifiedProduct>> orderVerify(Context context, String signedData, String signature) { StringBuilder sbUrl = new StringBuilder(); sbUrl.append(DOMAIN); sbUrl.append("android/order_verify/"); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("token", Util.getToken(Util.getSignature(context)))); params.add(new BasicNameValuePair("token_method", "ndk")); params.add(new BasicNameValuePair("signed_data", signedData)); params.add(new BasicNameValuePair("signature", signature)); UrlEncodedFormEntity urlEncodedFormEntity = null; try { urlEncodedFormEntity = new UrlEncodedFormEntity(params, HTTP.UTF_8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } String str = null; try { str = HttpUtil.post(sbUrl.toString(), urlEncodedFormEntity); } catch (Exception e) { return SPResult.getSeverErrInstance(context); } return new VerifiedProductListParser(context).getResult(str); }
From source file:br.com.atmatech.sac.webService.WebServiceFinanceiro.java
public List<FinanceiroBeans> getFinanceiro(String url, String user, String password) throws IOException { String chave = ""; HttpPost post = new HttpPost(url); boolean result = false; /* Configura os parmetros do POST */ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("login", user)); nameValuePairs.add(new BasicNameValuePair("senha", password)); nameValuePairs.add(new BasicNameValuePair("x", "26")); nameValuePairs.add(new BasicNameValuePair("y", "26")); post.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8)); // post.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 5.1; rv:18.0) Gecko/20100101 Firefox/18.0"); HttpResponse response = client.execute(post); // System.out.println("Login form get: " + response.getStatusLine()); EntityUtils.consume(response.getEntity()); HttpPost get = new HttpPost("http://atma.serveftp.com/atma/view/index.php?page=BAIXAR&mostrar=1"); get.setEntity(new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8)); response = client.execute(get);// w ww. j av a 2 s . c o m BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line; // // Grava pagina no arquivo FileWriter out = new FileWriter("./logfin.txt"); PrintWriter gravarArq = new PrintWriter(out); int indexant = 11; boolean doc = true; boolean cliente = true; boolean valor = true; boolean vencimento = true; boolean contato = true; boolean tel = true; String tdoc = ""; String tcliente = ""; float tvalor = 0; Date tvencimento = null; String tcontato = ""; String ttel = ""; List<FinanceiroBeans> lfb = new ArrayList<>(); while ((line = rd.readLine()) != null) { if (line.contains("<tr><td>")) { //gravarArq.print(line+"\n"); line = line.replace("<tr><td>", "\n").replace("</td></tr>", "\n"); line = line.replace("</td><td>", ";") .replace("</td><td align='center'><a class='btn default' target='_blank'", ";") .replace("</i></a>", ":"); gravarArq.print(line + "\n"); for (int i = 0; i < line.length(); i++) { if (doc && (indexant != i)) { if (line.charAt(i) == ';') { tdoc = line.substring(indexant + 1, i); indexant = i; doc = false; } } else { if ((!doc) && (cliente) && (indexant != i)) { if (line.charAt(i) == ';') { tcliente = line.substring(indexant + 1, i); indexant = i; cliente = false; } } else { if ((!doc) && (!cliente) && (valor) && (indexant != i)) { if (line.charAt(i) == ';') { tvalor = Float.valueOf(line.substring(indexant + 1, i)); indexant = i; valor = false; } } else { if ((!doc) && (!cliente) && (!valor) && (vencimento) && (indexant != i)) { if (line.charAt(i) == ';') { String data = line.substring(indexant + 1, i).replace("/", "."); int ind1 = data.indexOf("."); int ind2 = data.indexOf(".", ind1 + 1); String dd = data.substring(0, ind1); String mm = data.substring(ind1 + 1, ind2); String yyyy = data.substring(ind2 + 1); tvencimento = new Date(Integer.parseInt(yyyy) - 1900, Integer.parseInt(mm) - 1, Integer.parseInt(dd)); indexant = i; vencimento = false; } } else { if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (contato) && (indexant != i)) { if (line.charAt(i) == ';') { tcontato = line.substring(indexant + 1, i); indexant = i; contato = false; } } else { if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato) && (tel) && (indexant != i)) { if (line.charAt(i) == ';') { ttel = line.substring(indexant + 1, i); indexant = i; tel = false; } } else { if ((!doc) && (!cliente) && (!valor) && (!vencimento) && (!contato) && (!tel) && (line.charAt(i) == ':')) { indexant = i + 2; FinanceiroBeans fb = new FinanceiroBeans(); fb.setCliente(tcliente); fb.setContato(tcontato); fb.setDoc(tdoc); fb.setTelcel(ttel); fb.setValor(tvalor); fb.setVencimento(tvencimento); lfb.add(fb); doc = true; cliente = true; valor = true; vencimento = true; contato = true; tel = true; } } } } } } } } } } out.close(); return lfb; }
From source file:cn.aofeng.demo.httpclient.HttpClientBasic.java
public void post() throws ClientProtocolException, IOException { List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("chinese", "")); params.add(new BasicNameValuePair("english", "")); UrlEncodedFormEntity entity = new UrlEncodedFormEntity(params, _charset); CloseableHttpClient client = HttpClients.createDefault(); HttpPost post = new HttpPost(_targetHost + "/post"); post.addHeader("Cookie", "character=abcdefghijklmnopqrstuvwxyz; sign=abc-123-jkl-098"); post.setEntity(entity);/*from ww w .j a va2 s . c om*/ CloseableHttpResponse response = client.execute(post); processResponse(response); }
From source file:com.jzc.rfid.cl.listeners.RFIDTagGainListener.java
public void tagGained(TagGainEvent tagGainEvent) { System.out.println(Main.readerId + " " + tagGainEvent.getValue()); final String tagValue = tagGainEvent.getValue(); new Thread(new Runnable() { public void run() { try { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("cardId", tagValue)); qparams.add(new BasicNameValuePair("readerId", Integer.toString(Main.readerId))); String url = "http://www.electric20.com/thermaPref/cardEvent.php"; HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new UrlEncodedFormEntity(qparams, HTTP.UTF_8)); HttpClient httpClient = new DefaultHttpClient(); //HttpHost proxy = new HttpHost("mainproxy.nottingham.ac.uk",8080); //httpClient.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); httpClient.execute(httpPost); httpClient.getConnectionManager().closeExpiredConnections(); System.out.println(httpPost.getURI()); } catch (Exception e) { e.printStackTrace();//from w ww.j av a 2 s .c o m } } }).start(); try { rfid.setLEDOn(!rfid.getLEDOn()); } catch (PhidgetException e) { e.printStackTrace(); } }
From source file:nz.co.jsrsolutions.tideservice.scraper.provider.EasyTideRegionSelectClickHttpPost.java
public EasyTideRegionSelectClickHttpPost(URI uri, String viewState, String eventValidation, String areaId, String region) {// w w w. ja va 2s.c o m 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", "")); nvps.add(new BasicNameValuePair("__EVENTARGUMENT", "")); nvps.add(new BasicNameValuePair("__LASTFOCUS", "")); nvps.add(new BasicNameValuePair("PortSelectionAreas:ddlAreas", areaId)); nvps.add(new BasicNameValuePair("PortSelectionAreas:ddlRegions", region)); nvps.add(new BasicNameValuePair("PortSelectionAreas:butShowPorts:_ctl0.x", "51")); nvps.add(new BasicNameValuePair("PortSelectionAreas:butShowPorts:_ctl0.y", "22")); setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); }
From source file:fr.shywim.antoinedaniel.utils.GcmUtils.java
public static void sendRegistrationIdToBackend(Context context, String regid, int version) { try {// w w w.jav a2s. c om HttpPost post = new HttpPost(context.getString(R.string.api_register)); List<NameValuePair> params = new ArrayList<>(2); params.add(new BasicNameValuePair("regid", regid)); params.add(new BasicNameValuePair("version", Integer.toString(version))); post.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); HttpClient client = new DefaultHttpClient(); HttpResponse response = client.execute(post); int responseCode = response.getStatusLine().getStatusCode(); if (responseCode == 200 || responseCode == 201) { context.getSharedPreferences(AppConstants.GOOGLE_PREFS, Context.MODE_PRIVATE).edit() .putBoolean(AppConstants.GOOGLE_GCM_REGISTERED, true).apply(); } } catch (IOException e) { Crashlytics.logException(e); } }
From source file:biz.shadowservices.DegreesToolbox.HttpPoster.java
public HttpPoster(URI uri, List<? extends NameValuePair> values) { httppost = new HttpPost(uri); try {/*from w w w .ja v a2s. co m*/ httppost.setEntity(new UrlEncodedFormEntity(values, HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, "Error: Unsupported encoding exception on " + httppost.getURI()); } }
From source file:jp.ambrosoli.quickrestclient.apache.params.ApacheEnclosingParamBuilder.java
public UrlEncodedFormEntity createConformedParams(final List<NameValueObject> params, final String charset) { try {/*from w ww. ja v a 2s . c o m*/ List<NameValuePair> paramList = this.createNameValuePairList(params); String encoding = StringUtil.isNotEmpty(charset) ? charset : StringUtil.DEFAULT_ENCODING; return new UrlEncodedFormEntity(paramList, encoding); } catch (UnsupportedEncodingException e) { throw new UnsupportedEncodingRuntimeException(e); } }
From source file:bad.robot.http.apache.HttpRequestToEntity.java
@Override public void visit(FormUrlEncodedMessage formUrlEncodedMessage) { try {//from w w w. jav a 2 s . co m FormParameters content = formUrlEncodedMessage.getContent(); entity = new UrlEncodedFormEntity(content.transform(asApacheNameValuePair()), formUrlEncodedMessage.characterSet()); } catch (UnsupportedEncodingException e) { throw new HttpException(e); } }
From source file:br.cefetrj.sagitarii.nunki.comm.WebClient.java
public void doPost(String action, String parameter, String content) throws Exception { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); HttpPost httppost = new HttpPost(gf.getHostURL() + "/" + action); // Request parameters and other properties. List<NameValuePair> params = new ArrayList<NameValuePair>(2); params.add(new BasicNameValuePair(parameter, content)); httppost.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); httpClient.execute(httppost);//from w ww. j a v a2 s.c o m httpClient.close(); }