List of usage examples for org.apache.http.protocol HTTP UTF_8
String UTF_8
To view the source code for org.apache.http.protocol HTTP UTF_8.
Click Source Link
From source file:net.emphased.vkclient.VkClient.java
/** * Login to Vk site./*from www .j av a 2s. c om*/ * @param email email for login. * @param password password for login. * @return API instance. * @throws VkException if login failed. */ public VkApi login(String email, String password) throws IOException, VkException { CookieStore cookieStore = getCookieStore(email); HttpContext httpContext = getHttpContext(cookieStore); List<NameValuePair> params = new ArrayList<NameValuePair>(); params.add(new BasicNameValuePair("noredirect", "1")); params.add(new BasicNameValuePair("email", email)); params.add(new BasicNameValuePair("pass", password)); HttpPost post = new HttpPost(DEFAULT_LOGIN_URL); post.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8)); post.addHeader("X-Requested-With", "XMLHttpRequest"); HttpResponse resp = _httpClient.execute(post, httpContext); String respContent = EntityUtils.toString(resp.getEntity()); VkLoginResult loginResult = _objectMapper.readValue(respContent, VkLoginResult.class); if (!StringUtils.isEmpty(loginResult.getErrorMessage())) { throw new VkException(loginResult.getErrorMessage()); } Cookie sessionCookie = CookieUtils.findCookie(cookieStore, SESSION_COOKIE); if (sessionCookie == null) { throw new VkException("No session cookie found"); } // Store LoginResult for future cookie-based logins. BasicClientCookie sessionInfoCookie = new BasicClientCookie(SESSION_INFO_COOKIE, respContent); sessionInfoCookie.setExpiryDate(sessionCookie.getExpiryDate()); cookieStore.addCookie(sessionInfoCookie); return createApi(httpContext, loginResult); }
From source file:cvut.fel.mobilevoting.murinrad.communications.Connection.java
/** * Initializes the HTTP connection/*from w w w .ja v a 2 s .c o m*/ */ public void InitializeUnsecure() { try { run = false; port = server.getPort(); HttpParams params = new BasicHttpParams(); HttpConnectionParams.setConnectionTimeout(params, 3000); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); schemeRegistry = new SchemeRegistry(); Scheme http = new Scheme("http", new PlainSocketFactory(), port); schemeRegistry.register(http); HttpPost post = new HttpPost(server.getAddress()); SingleClientConnManager cm = new SingleClientConnManager(post.getParams(), schemeRegistry); connection = new DefaultHttpClient(cm, params); this.connection.addResponseInterceptor(new Interceptor(this)); notifyOfProggress(); postAndRecieve("OPTIONS", "/", null, null, true); // notifyOfProggress(false); instance = this; } catch (IllegalStateException ex) { } catch (Exception ex) { Log.e("Android mobile voting", "INIT HTTP error " + ex.toString()); showNoConError(); } }
From source file:com.blackboard.LearnServer.java
private AbstractHttpClient getTrustAllSSLHttpClient() { try {//from w ww.j av a 2 s .co m KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(null, null); SSLSocketFactory sf = new TrustAllSSLSocketFactory(trustStore); sf.setHostnameVerifier(SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER); HttpParams params = new BasicHttpParams(); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80)); registry.register(new Scheme("https", sf, 443)); ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry); return new DefaultHttpClient(ccm, params); } catch (Exception e) { System.out.println("WARNING: Could not create Trust All SSL client, using default" + e.getMessage()); return new DefaultHttpClient(); } }
From source file:de.felixschulze.acra.JsonSender.java
private void sendHttpPost(String data, URL url, String login, String password) { DefaultHttpClient httpClient = new DefaultHttpClient(); try {// w w w . jav a2s .c o m HttpPost httPost = new HttpPost(url.toString()); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("json", data)); httPost.setEntity(new UrlEncodedFormEntity(nameValuePairs, HTTP.UTF_8)); HttpResponse httpResponse = httpClient.execute(httPost); Log.d(LOG_TAG, "Server Status: " + httpResponse.getStatusLine()); Log.d(LOG_TAG, "Server Response: " + EntityUtils.toString(httpResponse.getEntity())); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { httpClient.getConnectionManager().shutdown(); } }
From source file:com.brightcove.com.uploader.helper.LoginHelper.java
public void loginToWacky(URI pUri, String user, String pass) throws IOException { NameValuePair[] data = { new BasicNameValuePair("username", user), new BasicNameValuePair("password", pass), new BasicNameValuePair("u", "/services/internal/index.jsp"), new BasicNameValuePair("Submit", "Post") }; mLog.info(pUri);/*from w w w . j a v a 2 s .c o m*/ HttpPost method = new HttpPost(pUri); method.setHeader("Host", "services.brightcove.com"); method.setEntity(new UrlEncodedFormEntity(Arrays.asList(data), HTTP.UTF_8)); HttpResponse resp = client.execute(method); Header[] headers = resp.getHeaders("Set-Cookie"); for (int i = 0; i < headers.length; i++) { mLog.info(headers[i].getName() + " " + headers[i].getValue()); String value = headers[i].getValue(); if (value.contains("BC_TOKEN_WACKY")) { admin_token = value.substring(value.indexOf("BC_TOKEN_WACKY=") + 9); admin_token = admin_token.substring(0, admin_token.indexOf(";")); mLog.info(token); } } }
From source file:org.projectbuendia.client.net.GsonRequest.java
@Override protected Response<T> parseNetworkResponse(NetworkResponse response) { try {/* w ww. ja v a 2s . c o m*/ String json = new String(response.data, HTTP.UTF_8); // TODO: HttpHeaderParser.parseCharset(response.mHeaders). Gson gsonParser = mGson.create(); Log.d("SyncAdapter", "parsing response"); if (mIsArray) { JsonParser parser = new JsonParser(); JsonArray array = (JsonArray) parser.parse(json); ArrayList<T> elements = new ArrayList<>(); for (int i = 0; i < array.size(); i++) { elements.add(gsonParser.fromJson(array.get(i).toString(), mClazz)); } return (Response<T>) Response.success(elements, HttpHeaderParser.parseCacheHeaders(response)); } else { return Response.success(gsonParser.fromJson(json, mClazz), HttpHeaderParser.parseCacheHeaders(response)); } } catch (UnsupportedEncodingException e) { return Response.error(new ParseError(e)); } catch (JsonSyntaxException e) { return Response.error(new ParseError(e)); } catch (Exception e) { return Response.error(new ParseError(e)); } }
From source file:cn.org.eshow.framwork.http.AbRequestParams.java
/** * ??./*ww w. j a v a 2 s . co m*/ * * @return the param string */ public String getParamString() { List<BasicNameValuePair> paramsList = new LinkedList<BasicNameValuePair>(); for (ConcurrentHashMap.Entry<String, String> entry : urlParams.entrySet()) { paramsList.add(new BasicNameValuePair(entry.getKey(), entry.getValue())); } return URLEncodedUtils.format(paramsList, HTTP.UTF_8); }
From source file:com.ushahidi.android.app.net.MainHttpClient.java
public static HttpResponse PostURL(String URL, List<NameValuePair> data, String Referer) throws IOException { Preferences.httpRunning = true; // Dipo Fix/*from w w w.j a va 2 s .co m*/ try { // wrap try around because this constructor can throw Error final HttpPost httpost = new HttpPost(URL); // org.apache.http.client.methods. if (Referer.length() > 0) { httpost.addHeader("Referer", Referer); } if (data != null) { try { // NEED THIS NOW TO FIX ERROR 417 httpost.getParams().setBooleanParameter("http.protocol.expect-continue", false); httpost.setEntity(new UrlEncodedFormEntity(data, HTTP.UTF_8)); } catch (final UnsupportedEncodingException e) { // TODO Auto-generated catch block e.printStackTrace(); Preferences.httpRunning = false; return null; } } // Post, check and show the result (not really spectacular, but // works): try { HttpResponse response = httpClient.execute(httpost); Preferences.httpRunning = false; return response; } catch (final Exception e) { } } catch (final Exception e) { e.printStackTrace(); } Preferences.httpRunning = false; return null; }
From source file:io.coldstart.android.API.java
public String createGCMAccount(String EmailAddress, String Password, String gcmID, String deviceID) throws ClientProtocolException, IOException { HttpPost httpost = new HttpPost("https://api.coldstart.io/" + API.API_VERSION + "/register"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("version", Integer.toString(API.API_VERSION))); nvps.add(new BasicNameValuePair("useremail", EmailAddress)); nvps.add(new BasicNameValuePair("gcmid", gcmID)); nvps.add(new BasicNameValuePair("deviceid", deviceID)); if (!Password.equals("")) nvps.add(new BasicNameValuePair("password", API.md5(Password))); httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); HttpResponse response = httpclient.execute(httpost); String rawJSON = EntityUtils.toString(response.getEntity()); Log.e("rawJSON", rawJSON); response.getEntity().consumeContent(); try {/*from w ww. j a v a2 s .com*/ JSONObject newAccountObject = new JSONObject(rawJSON); if (newAccountObject.has("apikey")) { return newAccountObject.getString("apikey"); } else { return null; } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); return null; } }
From source file:com.fanfou.app.opensource.util.NetworkHelper.java
private static final HttpParams createHttpParams() { final HttpParams params = new BasicHttpParams(); HttpProtocolParams.setUseExpectContinue(params, false); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1); ConnManagerParams.setTimeout(params, NetworkHelper.SOCKET_TIMEOUT_MS); HttpConnectionParams.setConnectionTimeout(params, NetworkHelper.CONNECTION_TIMEOUT_MS); HttpConnectionParams.setSoTimeout(params, NetworkHelper.SOCKET_TIMEOUT_MS); ConnManagerParams.setMaxConnectionsPerRoute(params, new ConnPerRouteBean(NetworkHelper.MAX_TOTAL_CONNECTIONS)); ConnManagerParams.setMaxTotalConnections(params, NetworkHelper.MAX_TOTAL_CONNECTIONS); HttpConnectionParams.setStaleCheckingEnabled(params, false); HttpConnectionParams.setTcpNoDelay(params, true); HttpConnectionParams.setSocketBufferSize(params, NetworkHelper.SOCKET_BUFFER_SIZE); HttpClientParams.setRedirecting(params, false); HttpProtocolParams.setUserAgent(params, "FanFou for Android/" + AppContext.appVersionName); return params; }