List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters)
From source file:com.github.robozonky.integrations.zonkoid.ZonkoidConfirmationProvider.java
private static HttpEntity getFormData(final RequestId requestId, final int loanId, final int amount) throws UnsupportedEncodingException { final List<NameValuePair> nvps = Arrays.asList(new BasicNameValuePair("clientApp", CLIENT_APP), new BasicNameValuePair("username", requestId.getUserId()), new BasicNameValuePair("loanId", String.valueOf(loanId)), new BasicNameValuePair("preferredAmount", String.valueOf(amount))); return new UrlEncodedFormEntity(nvps); }
From source file:me.ziccard.secureit.async.upload.DelegatedPositionUploaderTask.java
@Override protected Void doInBackground(Void... params) { while (true) { Log.i("DelegatedPositionUploaderTask", "Started"); HttpClient client = new DefaultHttpClient(); /*/* w ww . j a v a2s. com*/ * Send the last * detected position to /phone/phoneId/position [POST] */ HttpPost request = new HttpPost( Remote.HOST + Remote.PHONES + "/" + phoneId + Remote.DELEGATED_UPLOAD_POSITION); /* * Adding latitude and longitude */ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("lat", "" + lat)); nameValuePairs.add(new BasicNameValuePair("long", "" + lng)); nameValuePairs.add(new BasicNameValuePair("access_key", accessKey)); try { request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = client.execute(request); BufferedReader reader = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), "UTF-8")); StringBuilder builder = new StringBuilder(); for (String line = null; (line = reader.readLine()) != null;) { builder.append(line).append("\n"); } Log.i("PeriodicPositionUploaderTask", "Response:\n" + builder.toString()); if (response.getStatusLine().getStatusCode() != 200) { throw new HttpException(); } } catch (Exception e) { Log.e("DelegatedPositionUploaderTask", "Error uploading delegated location"); } } }
From source file:com.pti.mates.ServerUtilities.java
/** * Register this account/device pair within the server. *//*from ww w . ja v a2 s . c o m*/ public static void register(String fbid, String regId, Context ctx) { Utils utils = new Utils(ctx); DefaultHttpClient client = new MyHttpClient(ctx); HttpPost post = new HttpPost("https://54.194.14.115:443/register"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(1); nameValuePairs.add(new BasicNameValuePair("matesid", fbid)); Log.d("REGISTERBACK", "matesId = " + fbid); nameValuePairs.add(new BasicNameValuePair("gcmid", regId)); Log.d("regIdBACK", regId); try { post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } catch (UnsupportedEncodingException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } // Execute the Post call and obtain the response HttpResponse postResponse; try { Log.d("REGISTERBACK", "ENTRO TRY"); postResponse = client.execute(post); HttpEntity responseEntity = postResponse.getEntity(); InputStream is = responseEntity.getContent(); s = utils.convertStreamToString(is); Log.d("S REGISTER", s); } catch (ClientProtocolException e) { Log.e("ERROR", e.toString()); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); Log.e("ERROR", e.toString()); s = "ERROR: " + e.toString() + " :("; } Log.d("CHIVATO registe", "FIN THREAD"); //doRegister = new DoRegister(fbid,regId,ctx); //doRegister.execute(); Intent intent = new Intent(ctx, LogOk.class); ctx.startActivity(intent); }
From source file:org.jboss.pnc.auth.client.SimpleOAuthConnect.java
private static String[] connect(String url, Map<String, String> urlParams) throws ClientProtocolException, IOException { CloseableHttpClient httpclient = HttpClients.createDefault(); HttpPost httpPost = new HttpPost(url); // add header httpPost.setHeader("Content-Type", "application/x-www-form-urlencoded"); List<BasicNameValuePair> urlParameters = new ArrayList<BasicNameValuePair>(); for (String key : urlParams.keySet()) { urlParameters.add(new BasicNameValuePair(key, urlParams.get(key))); }//from w ww. j a v a 2 s .co m httpPost.setEntity(new UrlEncodedFormEntity(urlParameters)); CloseableHttpResponse response = httpclient.execute(httpPost); String refreshToken = ""; String accessToken = ""; try { BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); String line = ""; while ((line = rd.readLine()) != null) { if (line.contains("refresh_token")) { String[] respContent = line.split(","); for (int i = 0; i < respContent.length; i++) { String split = respContent[i]; if (split.contains("refresh_token")) { refreshToken = split.split(":")[1].substring(1, split.split(":")[1].length() - 1); } if (split.contains("access_token")) { accessToken = split.split(":")[1].substring(1, split.split(":")[1].length() - 1); } } } } } finally { response.close(); } return new String[] { accessToken, refreshToken }; }
From source file:com.gmail.at.faint545.tasks.HistoryDownloadTask.java
@Override protected String doInBackground(Void... params) { HttpClient client = new DefaultHttpClient(); HttpPost request = new HttpPost(url); ArrayList<NameValuePair> arguments = new ArrayList<NameValuePair>(); arguments.add(new BasicNameValuePair(SabnzbdConstants.APIKEY, api)); arguments.add(new BasicNameValuePair(SabnzbdConstants.OUTPUT, SabnzbdConstants.OUTPUT_JSON)); arguments.add(new BasicNameValuePair(SabnzbdConstants.MODE, SabnzbdConstants.MODE_HISTORY)); try {/*from ww w . ja v a 2 s . c om*/ request.setEntity(new UrlEncodedFormEntity(arguments)); HttpResponse result = client.execute(request); InputStream inStream = result.getEntity().getContent(); BufferedReader br = new BufferedReader(new InputStreamReader(inStream), 8); StringBuilder jsonStringBuilder = new StringBuilder(); String line; while ((line = br.readLine()) != null) { if (line.length() > 0) { jsonStringBuilder.append(line); } } br.close(); inStream.close(); return jsonStringBuilder.toString(); } catch (ClientProtocolException e) { return ClientProtocolException.class.getName(); } catch (IOException e) { return IOException.class.getName(); } }
From source file:org.kei.android.phone.mangastore.http.HttpTaskAdd.java
@Override protected JSONArray doInBackground(final String... params) { try {//w w w . ja v a 2 s . c om final HttpClient client = new DefaultHttpClient(); final HttpPost httpPost = new HttpPost(params[0]); final List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("android_name", params[1])); nameValuePairs.add(new BasicNameValuePair("android_password", params[2])); nameValuePairs.add(new BasicNameValuePair("android_i", params[3])); nameValuePairs.add(new BasicNameValuePair("android_l", params[4])); nameValuePairs.add(new BasicNameValuePair("android_v", params[5])); nameValuePairs.add(new BasicNameValuePair("android_y", params[6])); nameValuePairs.add(new BasicNameValuePair("android_s", params[7])); nameValuePairs.add(new BasicNameValuePair("android_t", params[8])); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); final HttpResponse response = client.execute(httpPost); final StatusLine statusLine = response.getStatusLine(); final int code = statusLine.getStatusCode(); if (code != 200) { if (code == CODE_EXISTS) throw new IOException("" + code); throw new IOException("The server has responded an error " + code); } } catch (final Exception e) { t.runOnUiThread(new Runnable() { @Override public void run() { t.onTaskError(e); } }); } return null; }
From source file:org.n52.oss.ui.controllers.AdminController.java
@RequestMapping(method = RequestMethod.POST, value = "/validate") public String validateUser(@ModelAttribute(value = "username") String username, ModelMap map) { try {/*from w w w . j a v a 2 s . c o m*/ UserDetails userDetails = (UserDetails) SecurityContextHolder.getContext().getAuthentication() .getPrincipal(); String token = userDetails.getPassword(); HttpPost post = new HttpPost(OSSConstants.BASE_URL + "/OpenSensorSearch/api/user/validate"); List<NameValuePair> pairs = new ArrayList<NameValuePair>(); pairs.add(new BasicNameValuePair("username", username)); pairs.add(new BasicNameValuePair("auth_token", token)); post.setEntity(new UrlEncodedFormEntity(pairs)); HttpClient client = new DefaultHttpClient(); HttpResponse resp = client.execute(post); map.put("ValidationCalled", true); if (resp.getStatusLine().getStatusCode() == 200) { map.put("ValidationMsg", username + " validated succesfully"); } else { map.put("ValidationMsg", username + " couldn't be validated!"); } return "admin/validate"; } catch (Exception e) { map.put("ValidationCalled", true); map.put("ValidationMsg", "Validation couldn't be done at the moment!"); return "admin/validate"; } }
From source file:com.lillicoder.newsblurry.login.LoginTask.java
@Override protected LoginResponse doInBackground(String... params) { LoginResponse response = null;// w ww.j a v a 2 s.c o m try { // Create the HttpPost instance for this login request and attach the login parameters. Context context = this.getContext(); String loginUrl = context.getString(R.string.api_loginUrl); HttpPost loginPost = new HttpPost(loginUrl); List<NameValuePair> loginParameters = this.getLoginParameters(params[0], params[1]); loginPost.setEntity(new UrlEncodedFormEntity(loginParameters)); // Pull entity and parse JSON response. HttpResponse httpResponse = this.executeWebRequest(loginPost); JSONObject responseJson = this.getJsonFromResponse(httpResponse); LoginResponseParser parser = new LoginResponseParser(); response = parser.parseLoginResponse(responseJson); } catch (IndexOutOfBoundsException e) { Log.e(TAG, EXCEPTION_UNABLE_TO_GET_USER_NAME_AND_PASSWORD_PARAMS, e); this.setException(new InvalidUserCredentialsException(e)); } catch (ApiRequestException e) { Log.e(TAG, EXCEPTION_API_REQUEST_FAILED, e); this.setException(e); } catch (IOException e) { Log.e(TAG, EXCEPTION_FAILED_TO_PARSE_RESPONSE, e); this.setException(e); } catch (JSONException e) { Log.e(TAG, EXCEPTION_UNABLE_TO_CREATE_JSON_FROM_RESPONSE, e); this.setException(e); } return response; }
From source file:com.francelabs.datafari.utils.SendHttpRequest.java
public static String sendPost(String url, String agent, List<NameValuePair> urlParameters) throws Exception { HttpClient client = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setHeader("User-Agent", agent); // urlParameters.add(new BasicNameValuePair("sn", "C02G8416DRJM")); // urlParameters.add(new BasicNameValuePair("cn", "")); // urlParameters.add(new BasicNameValuePair("locale", "")); // urlParameters.add(new BasicNameValuePair("caller", "")); // urlParameters.add(new BasicNameValuePair("num", "12345")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); HttpResponse response = client.execute(post); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + post.getEntity()); System.out.println("Response Code : " + response.getStatusLine().getStatusCode()); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);/*from ww w. j av a 2 s .c om*/ } return result.toString(); }
From source file:HttpCilentExample.HttpCilentExample.java
private void sendPost(String url, List<NameValuePair> postParams) throws Exception { HttpPost post = new HttpPost(url); // add header post.setHeader("Host", "accounts.google.com"); post.setHeader("User-Agent", USER_AGENT); post.setHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8"); post.setHeader("Accept-Language", "en-US,en;q=0.5"); post.setHeader("Cookie", getCookies()); post.setHeader("Connection", "keep-alive"); post.setHeader("Referer", "https://accounts.google.com/ServiceLoginAuth"); post.setHeader("Content-Type", "application/x-www-form-urlencoded"); post.setEntity(new UrlEncodedFormEntity(postParams)); HttpResponse response = client.execute(post); int responseCode = response.getStatusLine().getStatusCode(); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + postParams); System.out.println("Response Code : " + responseCode); BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent())); StringBuffer result = new StringBuffer(); String line = ""; while ((line = rd.readLine()) != null) { result.append(line);//from w w w. ja va 2s. c o m } // System.out.println(result.toString()); }