List of usage examples for org.apache.http.client.entity UrlEncodedFormEntity UrlEncodedFormEntity
public UrlEncodedFormEntity(final Iterable<? extends NameValuePair> parameters)
From source file:com.technion.studybuddy.GCM.ServerUtilities.java
/** * Issue a POST request to the server./*from ww w . j a v a 2 s .co m*/ * * @param endpoint * POST address. * @param params * request parameters. * * @throws IOException * propagated from POST. */ public static void post(String endpoint, String regID) throws IOException { AndroidHttpClient client = AndroidHttpClient.newInstance("GetAuthCookieClient", ServerUtilities.activity); try { GoogleHttpContext httpContext = ServerUtilities.getContext(ServerUtilities.activity, Constants.SERVER_URL); HttpPost httpPost = new HttpPost(endpoint); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("regid", regID)); nameValuePairs.add(new BasicNameValuePair("model", getDeviceName())); nameValuePairs.add(new BasicNameValuePair("deviceID", Secure.getString(ServerUtilities.activity.getContentResolver(), Secure.ANDROID_ID))); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse res = client.execute(httpPost, httpContext); res.toString(); } catch (NotRegisteredException e) { // cannot be registered with play registration e.printStackTrace(); } finally { client.close(); } }
From source file:net.argilo.busfollower.ocdata.OCTranspoDataFetcher.java
public GetNextTripsForStopResult getNextTripsForStop(String stopNumber, String routeNumber) throws IOException, XmlPullParserException, IllegalArgumentException { validateStopNumber(stopNumber);// ww w .j a v a 2 s . co m validateRouteNumber(routeNumber); httpClient = new DefaultHttpClient(getHttpParams()); HttpPost post = new HttpPost("https://api.octranspo1.com/v1.1/GetNextTripsForStop"); List<NameValuePair> params = new ArrayList<NameValuePair>(4); params.add(new BasicNameValuePair("appID", context.getString(R.string.oc_transpo_application_id))); params.add(new BasicNameValuePair("apiKey", context.getString(R.string.oc_transpo_application_key))); params.add(new BasicNameValuePair("routeNo", routeNumber)); params.add(new BasicNameValuePair("stopNo", stopNumber)); post.setEntity(new UrlEncodedFormEntity(params)); HttpResponse response = httpClient.execute(post); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); XmlPullParser xpp = factory.newPullParser(); InputStream in = response.getEntity().getContent(); xpp.setInput(in, "UTF-8"); xpp.next(); // <soap:Envelope> xpp.next(); // <soap:Body> xpp.next(); // <GetRouteSummaryForStopResponse> xpp.next(); // <GetRouteSummaryForStopResult> GetNextTripsForStopResult result = new GetNextTripsForStopResult(context, db, xpp, stopNumber); in.close(); return result; }
From source file:org.teiid.resource.adapter.google.auth.ClientLoginHeaderFactory.java
public void login() { DefaultHttpClient httpclient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost("https://www.google.com/accounts/ClientLogin"); //$NON-NLS-1$ List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("Email", username)); //$NON-NLS-1$ nvps.add(new BasicNameValuePair("Passwd", password)); //$NON-NLS-1$ nvps.add(new BasicNameValuePair("accountType", "GOOGLE")); //$NON-NLS-1$ //$NON-NLS-2$ nvps.add(new BasicNameValuePair("source", "ClientLoginHttpFactory")); //$NON-NLS-1$ //$NON-NLS-2$ nvps.add(new BasicNameValuePair("service", "wise")); //$NON-NLS-1$ //$NON-NLS-2$ HttpResponse response = null;// w w w .j av a 2s .c o m try { httpPost.setEntity(new UrlEncodedFormEntity(nvps)); response = httpclient.execute(httpPost); } catch (Exception ex) { throw new SpreadsheetAuthException("Error when attempting Client Login", ex); } if (response.getStatusLine().getStatusCode() != 200) { String msg = null; msg = response.getStatusLine().getStatusCode() + ": " + response.getStatusLine().getReasonPhrase(); throw new SpreadsheetAuthException("Error when attempting Client Login: " + msg); } BufferedReader br = null; try { br = new BufferedReader( new InputStreamReader(response.getEntity().getContent(), Charset.forName("UTF-8"))); //$NON-NLS-1$ br.readLine(); br.readLine(); // Third line is the auth. // TODO Little hackish. Some idea how to solve this? authkey = br.readLine(); if (authkey == null) { throw new SpreadsheetAuthException("Authkey read from server is null"); } authkey = authkey.substring(authkey.indexOf('=') + 1); } catch (IOException e) { throw new SpreadsheetAuthException("Error reading Client Login response", e); } finally { if (br != null) try { br.close(); } catch (IOException e) { } } }
From source file:com.otaupdater.stats.ReportingService.java
private void report() { final Context context = getApplicationContext(); String deviceId = Utilities.getUniqueID(context); String deviceName = Utilities.getDevice(); String deviceCountry = Utilities.getCountryCode(context); String deviceCarrier = Utilities.getCarrier(context); String deviceCarrierId = Utilities.getCarrierId(context); Log.d(TAG, "SERVICE: Device ID=" + deviceId); Log.d(TAG, "SERVICE: Device Name=" + deviceName); Log.d(TAG, "SERVICE: Country=" + deviceCountry); Log.d(TAG, "SERVICE: Carrier=" + deviceCarrier); Log.d(TAG, "SERVICE: Carrier ID=" + deviceCarrierId); try {// w w w. j a v a 2 s . c om List<NameValuePair> kv = new ArrayList<NameValuePair>(5); kv.add(new BasicNameValuePair("hash", deviceId)); kv.add(new BasicNameValuePair("device", deviceName)); kv.add(new BasicNameValuePair("country", deviceCountry)); kv.add(new BasicNameValuePair("carrier", deviceCarrier)); kv.add(new BasicNameValuePair("carrier_id", deviceCarrierId)); HttpPost post = new HttpPost(Config.STATS_REPORT_URL); post.setEntity(new UrlEncodedFormEntity(kv)); HttpClient httpc = new DefaultHttpClient(); httpc.execute(post); Config.getInstance(context).setStatsLastReport(System.currentTimeMillis()); } catch (Exception e) { Log.e(TAG, "Got Exception", e); } ReportingServiceManager.setAlarm(context); stopSelf(); }
From source file:com.geeksville.android.GeeksvilleExceptionHandler.java
@Override protected void submit(Throwable e) { String theErrReport = getDebugReport(e); try {//from w ww . j a v a 2 s.c o m HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(submitURL); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("appname", mApp.getPackageName())); nameValuePairs.add(new BasicNameValuePair("content", theErrReport)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); BufferedReader respStream = new BufferedReader(new InputStreamReader(entity.getContent())); // String message = respStream.readLine(); respStream.close(); // Log.d("resp", message); } catch (IOException e1) { // Failure contacting geeksville, ignore it for now (FIXME) } }
From source file:ca.ualberta.cs.c301_crowdclient.CrowdClient.java
/** * Consumes the LIST operation of the service * @return JSON representation of the entry list * @throws Exception//from www . j a v a 2s . c o m */ public String listEntrys() throws Exception { String jsonStringVersion = new String(); List<BasicNameValuePair> nvps = new ArrayList<BasicNameValuePair>(); nvps.add(new BasicNameValuePair("action", "list")); httpPost.setEntity(new UrlEncodedFormEntity(nvps)); HttpResponse response = httpclient.execute(httpPost); String status = response.getStatusLine().toString(); HttpEntity entity = response.getEntity(); System.out.println(status); if (entity != null) { InputStream is = entity.getContent(); jsonStringVersion = convertStreamToString(is); } // and ensure it is fully consumed entity.consumeContent(); return jsonStringVersion; }
From source file:com.vkassin.mtrade.CSPLicense.java
boolean getLicense() { HttpClient httpclient = getNewHttpClient(); HttpPost httppost = new HttpPost(licenseURL); //licenseURL - url , (https://shop.gamma.kz/gs_cart/get_mobile_license) try {/*w ww. j a v a2 s .co m*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(3); nameValuePairs.add(new BasicNameValuePair("os", "android")); TelephonyManager telephonyManager = (TelephonyManager) Common.app_ctx .getSystemService(Context.TELEPHONY_SERVICE); nameValuePairs.add(new BasicNameValuePair("imei", telephonyManager.getDeviceId())); nameValuePairs.add(new BasicNameValuePair("code", getLicenseCode())); // , httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); if (entity != null) { String result = EntityUtils.toString(entity); // result Log.i(TAG, "license = " + result); // boolean b = this.installLicense(result); // Log.i(TAG, "write to file = " + b); } else return false; } catch (Exception e) { e.printStackTrace(); return false; } return true; }
From source file:com.pg.newsapp.http.NewsHttpClient.java
private String executePost() { String response = null;/* w w w . j a v a2 s .c o m*/ try { HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(mUrl); // Add data if (mValues != null && mValues.size() > 0) { List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(mValues.size()); for (String key : mValues.keySet()) { String value = mValues.get(key); nameValuePairs.add(new BasicNameValuePair(key, value)); } httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); } // Headers if (mHeaders != null && mHeaders.size() > 0) { for (String key : mHeaders.keySet()) { String value = mHeaders.get(key); httppost.addHeader(key, value); } } // ExecuteRequest HttpResponse httpResponse = httpclient.execute(httppost); response = new BasicResponseHandler().handleResponse(httpResponse); } catch (Exception e) { Log.w(TAG, "-- executePost " + e.getMessage()); } return response; }
From source file:com.groupxs.cordova.plugin.backgroundgpssend.AppService.java
public void getJSONfromURL(String url, List<NameValuePair> nameValuePairs) throws Exception { try {/*w w w . ja v a 2s . com*/ HttpClient httpclient = new DefaultHttpClient(); HttpPost post = new HttpPost(url); post.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse response = httpclient.execute(post); int responseStatus = response.getStatusLine().getStatusCode(); if (responseStatus == HttpStatus.SC_NO_CONTENT) Log.d("CordovaPlugin", "Data sent"); else Log.d("CordovaPlugin", "Data not sent. Response status: " + responseStatus); } catch (Exception e) { throw e; } }
From source file:com.autodesk.client.auth.OAuth2TwoLegged.java
private String post(String url, Map<String, String> formParameters, Map<String, String> headers) throws ClientProtocolException, IOException { HttpPost request = new HttpPost(url); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); for (String key : headers.keySet()) { request.setHeader(key, headers.get(key)); }// w w w . j a v a2s. c o m for (String key : formParameters.keySet()) { nvps.add(new BasicNameValuePair(key, formParameters.get(key))); } request.setEntity(new UrlEncodedFormEntity(nvps)); return execute(request); }