List of usage examples for org.apache.http.params CoreProtocolPNames USER_AGENT
String USER_AGENT
To view the source code for org.apache.http.params CoreProtocolPNames USER_AGENT.
Click Source Link
From source file:org.apache.marmotta.platform.core.util.http.HttpRequestUtil.java
/** * Set the <i>local part</i> of the User-Agent Header String. It will be suffixed with the * global part of the User-Agent, which is handled by the corresponding * {@link HttpClientService} implementation. * //from w w w . j a v a 2s . co m * @param request the request to modify * @param userAgentString the prefix of the User-Agent string which will be suffixed with a * LMF-global part handled b< the {@link HttpClientService} implementation. */ public static void setUserAgentString(HttpRequestBase request, String userAgentString) { request.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgentString); }
From source file:com.playhaven.android.req.UrlRequest.java
@Override public String call() throws MalformedURLException, IOException, PlayHavenException { HttpURLConnection connection = (HttpURLConnection) new URL(mInitialUrl).openConnection(); connection.setInstanceFollowRedirects(true); connection.setRequestProperty(CoreProtocolPNames.USER_AGENT, UserAgent.USER_AGENT); connection.getContent(); // .getHeaderFields() will return null if headers not accessed once before if (connection.getHeaderFields().containsKey(LOCATION_HEADER)) { return connection.getHeaderField(LOCATION_HEADER); } else {/*from www .ja v a 2s . c om*/ throw new PlayHavenException(); } }
From source file:eu.dime.ps.semantic.util.URLInputSource.java
public HttpResponse getHttpResponse() throws IOException { final HttpClient httpclient = new DefaultHttpClient(); try {//from w ww . j a v a 2 s . c o m final HttpGet httpget = new HttpGet(url.toString()); httpget.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (compatible; dimeBot; http://dime-project.eu/)"); if (accept != null) { httpget.setHeader("Accept", accept); } return httpclient.execute(httpget); } catch (final Exception e) { return null; } }
From source file:com.vintank.slack4j.webhook.SlackWebHook.java
public void send(Payload payload) throws IOException { HttpPost post = new HttpPost(url); try {/* w w w. ja v a2 s . c o m*/ post.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Slack4j/1.0"); post.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, "UTF-8"); HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(AllClientPNames.CONNECTION_TIMEOUT, 5000); client.getParams().setParameter(AllClientPNames.SO_TIMEOUT, 5000); List<NameValuePair> nvps = new ArrayList<NameValuePair>(1); nvps.add(new BasicNameValuePair("payload", MAPPER.writeValueAsString(payload))); post.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); client.execute(post); } finally { post.releaseConnection(); } }
From source file:com.limewoodmedia.nsdroid.LoadingHelper.java
public static Bitmap loadFlag(String url, Context context) throws ClientProtocolException, IOException { if (url == null || url.length() == 0) { // No flag to load return null; }//from ww w . j a v a 2 s . c om HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, API.getInstance(context).getUserAgent()); client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true); HttpGet get = new HttpGet(url); HttpResponse response = client.execute(get); InputStream stream = response.getEntity().getContent(); return BitmapFactory.decodeStream(stream); }
From source file:net.peterkuterna.android.apps.devoxxfrsched.util.HttpUtils.java
/** * Generate and return a {@link HttpClient} configured for general use, * including setting an application-specific user-agent string. *//*from w w w.j a va 2 s . c o m*/ public static HttpClient getHttpClient(Context context) { final DefaultHttpClient client = new DevoxxHttpClient(context); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, buildUserAgent(context)); client.addRequestInterceptor(new HttpRequestInterceptor() { public void process(HttpRequest request, HttpContext context) { // Add header to accept gzip content if (!request.containsHeader(HEADER_ACCEPT_ENCODING)) { request.addHeader(HEADER_ACCEPT_ENCODING, ENCODING_GZIP); } } }); client.addResponseInterceptor(new HttpResponseInterceptor() { public void process(HttpResponse response, HttpContext context) { // Inflate any responses compressed with gzip final HttpEntity entity = response.getEntity(); final Header encoding = entity.getContentEncoding(); if (encoding != null) { for (HeaderElement element : encoding.getElements()) { if (element.getName().equalsIgnoreCase(ENCODING_GZIP)) { response.setEntity(new InflatingEntity(response.getEntity())); break; } } } } }); return client; }
From source file:eu.morfeoproject.fast.catalogue.util.URLInputSource.java
public HttpResponse getHttpResponse() throws IOException { final HttpClient httpclient = new DefaultHttpClient(); try {/*from w w w . j av a 2s. co m*/ final HttpGet httpget = new HttpGet(url.toString()); httpget.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "FASTbot"); if (accept != null) httpget.setHeader("Accept", accept); return httpclient.execute(httpget); } catch (final Exception e) { return null; } }
From source file:org.red5.server.util.HttpConnectionUtil.java
/** * Returns a client with all our selected properties / params. * // w w w. ja v a 2 s . com * @return client */ public static final DefaultHttpClient getClient() { // create a singular HttpClient object DefaultHttpClient client = new DefaultHttpClient(connectionManager); // dont retry client.setHttpRequestRetryHandler(new DefaultHttpRequestRetryHandler(0, false)); // get the params for the client HttpParams params = client.getParams(); // establish a connection within x seconds params.setParameter(CoreConnectionPNames.SO_TIMEOUT, connectionTimeout); // no redirects params.setParameter(ClientPNames.HANDLE_REDIRECTS, false); // set custom ua params.setParameter(CoreProtocolPNames.USER_AGENT, userAgent); // set the proxy if the user has one set if ((System.getProperty("http.proxyHost") != null) && (System.getProperty("http.proxyPort") != null)) { HttpHost proxy = new HttpHost(System.getProperty("http.proxyHost").toString(), Integer.valueOf(System.getProperty("http.proxyPort"))); client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy); } return client; }
From source file:org.xwiki.extension.repository.xwiki.internal.httpclient.DefaultHttpClientFactory.java
@Override public HttpClient createClient(String user, String password) { DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, this.configuration.getUserAgent()); httpClient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 60000); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 10000); // Setup proxy ProxySelectorRoutePlanner routePlanner = new ProxySelectorRoutePlanner( httpClient.getConnectionManager().getSchemeRegistry(), ProxySelector.getDefault()); httpClient.setRoutePlanner(routePlanner); // Setup authentication if (user != null) { httpClient.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(user, password)); }//from w ww .java2s. co m return httpClient; }
From source file:net.vexelon.mobileops.MTLClient.java
/** * Initialize Http Client//w w w .j ava 2s.co m */ private void initHttpClient() { HttpParams params = new BasicHttpParams(); params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.TRUE); params.setParameter(CoreProtocolPNames.USER_AGENT, HTTP_USER_AGENT); //params.setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, HTTP.UTF_8); httpClient = new DefaultHttpClient(params); httpCookieStore = new BasicCookieStore(); httpClient.setCookieStore(httpCookieStore); }