Java 类org.apache.http.params.CoreProtocolPNames 实例源码

项目:android-project-gallery    文件:Wo2bAsyncHttpClient.java   
/**
 * 全局唯一的AsyncHttpClient对象
 * 
 * @return
 */
public static AsyncHttpClient newAsyncHttpClient()
{
    String userAgent = null;
    if (CDK.getInstance().getCDKContext() != null)
    {
        userAgent = CDK.getInstance().getCDKContext().getUserAgent();
    }
    if (userAgent == null)
    {
        userAgent = "Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; GT-I9300 Build/JSS15J) "
                + "AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.3022";
    }

    asyncHttpClient.getHttpClient().getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent + ".10");

    return asyncHttpClient;
}
项目:sbc-qsystem    文件:QSystemHtmlInstance.java   
private QSystemHtmlInstance() {
    this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).
        setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).
        setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).
        setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).
        setParameter(CoreProtocolPNames.ORIGIN_SERVER, "QSystemReportHttpServer/1.1");

    // Set up the HTTP protocol processor
    final BasicHttpProcessor httpproc = new BasicHttpProcessor();
    httpproc.addInterceptor(new ResponseDate());
    httpproc.addInterceptor(new ResponseServer());
    httpproc.addInterceptor(new ResponseContent());
    httpproc.addInterceptor(new ResponseConnControl());

    // Set up request handlers
    final HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpQSystemReportsHandler());

    // Set up the HTTP service
    this.httpService = new HttpService(
        httpproc,
        new DefaultConnectionReuseStrategy(),
        new DefaultHttpResponseFactory(), reqistry, this.params);
}
项目:yaacc-code    文件:YaaccUpnpServerService.java   
public RequestListenerThread(Context context) throws IOException, BindException {
    serversocket = new ServerSocket(PORT);
    params = new BasicHttpParams();
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    BasicHttpProcessor httpProcessor = new BasicHttpProcessor();
    httpProcessor.addInterceptor(new ResponseDate());
    httpProcessor.addInterceptor(new ResponseServer());
    httpProcessor.addInterceptor(new ResponseContent());
    httpProcessor.addInterceptor(new ResponseConnControl());

    // Set up the HTTP service
    this.httpService = new YaaccHttpService(httpProcessor, new DefaultConnectionReuseStrategy(), new DefaultHttpResponseFactory(), context);

}
项目:remote-files-sync    文件:RequestUserAgentHC4.java   
public void process(final HttpRequest request, final HttpContext context)
    throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    if (!request.containsHeader(HTTP.USER_AGENT)) {
        String s = null;
        final HttpParams params = request.getParams();
        if (params != null) {
            s = (String) params.getParameter(CoreProtocolPNames.USER_AGENT);
        }
        if (s == null) {
            s = this.userAgent;
        }
        if (s != null) {
            request.addHeader(HTTP.USER_AGENT, s);
        }
    }
}
项目:android-project-wo2b    文件:Wo2bAsyncHttpClient.java   
/**
 * 全局唯一的AsyncHttpClient对象
 * 
 * @return
 */
public static AsyncHttpClient newAsyncHttpClient()
{
    String userAgent = null;
    if (RockySdk.getInstance().getClientInfo() != null)
    {
        userAgent = RockySdk.getInstance().getClientInfo().getUserAgent();
    }
    if (userAgent == null)
    {
        userAgent = "Mozilla/5.0 (Linux; U; Android 4.3; zh-cn; GT-I9300 Build/JSS15J) "
                + "AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.3022";
    }

    asyncHttpClient.getHttpClient().getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent + ".10");

    return asyncHttpClient;
}
项目:Visit    文件:RequestUserAgentHC4.java   
public void process(final HttpRequest request, final HttpContext context)
    throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    if (!request.containsHeader(HTTP.USER_AGENT)) {
        String s = null;
        final HttpParams params = request.getParams();
        if (params != null) {
            s = (String) params.getParameter(CoreProtocolPNames.USER_AGENT);
        }
        if (s == null) {
            s = this.userAgent;
        }
        if (s != null) {
            request.addHeader(HTTP.USER_AGENT, s);
        }
    }
}
项目:Cytomine-client-autobuilder    文件:HttpClient.java   
public int postCookie(String data) throws Exception {
        HttpPost httpPost = new HttpPost(URL.toString());
        System.out.println("change user agent");
        HttpContext HTTP_CONTEXT = new BasicHttpContext();
        client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");

        HTTP_CONTEXT.setAttribute(CoreProtocolPNames.USER_AGENT, "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
        httpPost.setHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");

        if (isAuthByPrivateKey) httpPost.setHeaders(headersArray);
//        httpPost.addHeader("Content-Type","application/json")
//        httpPost.addHeader("host",this.host)
        log.debug("Post send :" + data.replace("\n", ""));
        //write data
        BasicHttpEntity entity = new BasicHttpEntity();
        entity.setContent(new ByteArrayInputStream(data.getBytes()));
        entity.setContentLength((long)data.getBytes().length);
        httpPost.setEntity(entity);
        response = client.execute(targetHost, httpPost, localcontext);
        return response.getStatusLine().getStatusCode();
    }
项目:dsworkbench    文件:ReportServer.java   
public RequestListenerThread(int port, final String docroot) throws IOException {
    this.serversocket = new ServerSocket(port);
    this.params = new SyncBasicHttpParams();
    this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024).setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true).setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = new ImmutableHttpProcessor(new HttpResponseInterceptor[]{
        new ResponseDate(),
        new ResponseServer(),
        new ResponseContent(),
        new ResponseConnControl()
    });

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpFileHandler());

    // Set up the HTTP service
    this.httpService = new HttpService(
            httpproc,
            new DefaultConnectionReuseStrategy(),
            new DefaultHttpResponseFactory(),
            reqistry,
            this.params);
}
项目:XiaomiOrder    文件:MainActivity.java   
String get_url_contents( String url , List<NameValuePair> params , CookieStore cookieStore ) {
    try {
        HttpClient client = MySSLSocketFactory.createMyHttpClient();
        client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
        HttpResponse response = null;
        if( cookieStore == null )
            response = client.execute( new HttpGet( params == null || params.size() == 0 ? url : url + "?" + URLEncodedUtils.format(params, "utf-8") ) );
        else {
            HttpContext mHttpContext = new BasicHttpContext();
            mHttpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
            response = client.execute( new HttpGet( params == null || params.size() == 0 ? url : url + "?" + URLEncodedUtils.format(params, "utf-8") ) , mHttpContext );
        }
        HttpEntity result = response.getEntity();
        if( result != null ) {
            InputStream mInputStream = result.getContent();
            String out = getStringFromInputStream(mInputStream);
            mInputStream.close();
            return out;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}
项目:openhab-hdl    文件:StreamClientImpl.java   
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(
            CoreProtocolPNames.PROTOCOL_VERSION,
            requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
    );

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Let's add the user-agent header on every request
    HttpProtocolParams.setUserAgent(
            localParams,
            getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
    );

    return new DefaultedHttpParams(localParams, globalParams);
}
项目:AndroidRobot    文件:HttpClientUtil.java   
/** 
 * 获取DefaultHttpClient对象 
 *  
 * @param charset 
 *            字符编码 
 * @return DefaultHttpClient对象 
 */  
private static DefaultHttpClient getDefaultHttpClient(final String charset) {  
    DefaultHttpClient httpclient = new DefaultHttpClient();  
    // 模拟浏览器,解决一些服务器程序只允许浏览器访问的问题  
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,  
            USER_AGENT);  
    httpclient.getParams().setParameter(  
            CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);  
    httpclient.getParams().setParameter(  
            CoreProtocolPNames.HTTP_CONTENT_CHARSET,  
            charset == null ? CHARSET_ENCODING : charset);  

    // 浏览器兼容性  
    httpclient.getParams().setParameter(ClientPNames.COOKIE_POLICY,  
            CookiePolicy.BROWSER_COMPATIBILITY);  
    // 定义重试策略  
    httpclient.setHttpRequestRetryHandler(requestRetryHandler);  

    return httpclient;  
}
项目:DroidDLNA    文件:StreamClientImpl.java   
protected HttpParams getRequestParams(StreamRequestMessage requestMessage) {
    HttpParams localParams = new BasicHttpParams();

    localParams.setParameter(
        CoreProtocolPNames.PROTOCOL_VERSION,
        requestMessage.getOperation().getHttpMinorVersion() == 0 ? HttpVersion.HTTP_1_0 : HttpVersion.HTTP_1_1
    );

    // DefaultHttpClient adds HOST header automatically in its default processor

    // Add the default user agent if not already set on the message
    if (!requestMessage.getHeaders().containsKey(UpnpHeader.Type.USER_AGENT)) {
        HttpProtocolParams.setUserAgent(
            localParams,
            getConfiguration().getUserAgentValue(requestMessage.getUdaMajorVersion(), requestMessage.getUdaMinorVersion())
        );
    }

    return new DefaultedHttpParams(localParams, globalParams);
}
项目:neembuu-uploader    文件:MediaFireUploadPlugin.java   
public static void fileUpload() throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    HttpPost httppost = new HttpPost(postURL);
    File file = new File("d:/hai.html");
    System.out.println(ukeycookie);
    httppost.setHeader("Cookie", ukeycookie + ";" + skeycookie + ";" + usercookie);
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("Now uploading your file into mediafire...........................");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();

    System.out.println(response.getStatusLine());
    if (resEntity != null) {
        System.out.println("Getting upload response key value..........");
        uploadresponsekey = EntityUtils.toString(resEntity);
        getUploadResponseKey();
        System.out.println("upload resoponse key " + uploadresponsekey);
    }
}
项目:neembuu-uploader    文件:WuploadUploaderPlugin.java   
public static void fileUpload() throws IOException {
    HttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    file = new File("/home/vigneshwaran/dinesh.txt");
    HttpPost httppost = new HttpPost(postURL);
    httppost.setHeader("Cookie", langcookie + ";" + sessioncookie + ";" + mailcookie + ";" + namecookie + ";" + rolecookie + ";" + orderbycookie + ";" + directioncookie + ";");
    MultipartEntity mpEntity = new MultipartEntity();
    ContentBody cbFile = new FileBody(file);
    mpEntity.addPart("files[]", cbFile);
    httppost.setEntity(mpEntity);
    System.out.println("Now uploading your file into wupload...........................");
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity resEntity = response.getEntity();
    System.out.println(response.getStatusLine());
    if (response.getStatusLine().getStatusCode() == 302
            && response.getFirstHeader("Location").getValue().contains("upload/done/")) {

        System.out.println("Upload successful :)");
    } else {
        System.out.println("Upload failed :(");
    }

}
项目:neembuu-uploader    文件:ZohoDocsUploaderPlugin.java   
public static void fileUpload() throws IOException {
        HttpClient httpclient = new DefaultHttpClient();
        httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
        file = new File("C:\\Documents and Settings\\dinesh\\Desktop\\GeDotttUploaderPlugin.java");
        HttpPost httppost = new HttpPost("https://docs.zoho.com/uploadsingle.do?isUploadStatus=false&folderId=0&refFileElementId=refFileElement0");
        httppost.setHeader("Cookie", cookies.toString());
        MultipartEntity mpEntity = new MultipartEntity();
        ContentBody cbFile = new FileBody(file);
        mpEntity.addPart("multiupload_file", cbFile);
        httppost.setEntity(mpEntity);
        System.out.println("Now uploading your file into zoho docs...........................");
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity resEntity = response.getEntity();
        System.out.println(response.getStatusLine());
        if (resEntity != null) {

            String tmp = EntityUtils.toString(resEntity);
//            System.out.println(tmp);
            if(tmp.contains("File Uploaded Successfully"))
                System.out.println("File Uploaded Successfully");

        }
        //    uploadresponse = response.getLastHeader("Location").getValue();
        //  System.out.println("Upload response : " + uploadresponse);
    }
项目:dlna-for-android    文件:HttpServer.java   
private HttpServer(WifiManager wifiManager) {
    this.wifiManager = wifiManager;
    this.listenPort = 0;

    this.handlerRegistry = new HttpRequestHandlerRegistry();

    this.params = new BasicHttpParams();
    this.params
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER,
                    "4thLineAndroidHttpServer/1.0")
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 5000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE,
                    8 * 1024)
            .setBooleanParameter(
                    CoreConnectionPNames.STALE_CONNECTION_CHECK, false)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);

    startServer();
}
项目:AntennaPodSP    文件:AntennapodHttpClient.java   
/**
 * Returns the HttpClient singleton.
 */
public static synchronized HttpClient getHttpClient() {
    if (httpClient == null) {
        if (AppConfig.DEBUG) Log.d(TAG, "Creating new instance of HTTP client");

        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreProtocolPNames.USER_AGENT, AppPreferences.USER_AGENT);
        params.setIntParameter("http.protocol.max-redirects", MAX_REDIRECTS);
        params.setBooleanParameter("http.protocol.reject-relative-redirect",
                false);
        HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
        HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
        HttpClientParams.setRedirecting(params, true);

        httpClient = new DefaultHttpClient(createClientConnectionManager(), params);
        // Workaround for broken URLs in redirection
        ((AbstractHttpClient) httpClient)
                .setRedirectHandler(new APRedirectHandler());
    }
    return httpClient;
}
项目:Stacks-Flashcards    文件:StudyStackCommunicator.java   
private String getJSONData(URI uri) throws IOException {
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android");
    HttpGet request = new HttpGet();
    request.setHeader("Content-Type", "text/plain; charset=utf-8");
    request.setURI(uri);
    HttpResponse response = client.execute(request);
    BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer stringBuffer = new StringBuffer("");
    String line;

    String NL = System.getProperty("line.separator");

    while ((line = in.readLine()) != null) {
        stringBuffer.append(line + NL);
    }
    in.close();

    return stringBuffer.toString();
}
项目:Stacks-Flashcards    文件:QuizletCommunicator.java   
private JSONObject getJSONObject(URI uri) throws IOException, JSONException {
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "android");
    HttpGet request = new HttpGet();
    request.setHeader("Content-Type", "text/plain; charset=utf-8");
    request.setURI(uri);
    HttpResponse response = client.execute(request);
    BufferedReader in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    StringBuffer stringBuffer = new StringBuffer("");
    String line;

    String NL = System.getProperty("line.separator");

    while ((line = in.readLine()) != null) {
        stringBuffer.append(line + NL);
    }
    in.close();

    return new JSONObject(stringBuffer.toString());
}
项目:olingo-odata4    文件:SocketFactoryHttpClientFactory.java   
@Override
public DefaultHttpClient create(final HttpMethod method, final URI uri) {
  final TrustStrategy acceptTrustStrategy = new TrustStrategy() {
    @Override
    public boolean isTrusted(final X509Certificate[] certificate, final String authType) {
      return true;
    }
  };

  final SchemeRegistry registry = new SchemeRegistry();
  try {
    final SSLSocketFactory ssf =
            new SSLSocketFactory(acceptTrustStrategy, SSLSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
    registry.register(new Scheme(uri.getScheme(), uri.getPort(), ssf));
  } catch (Exception e) {
    throw new ODataRuntimeException(e);
  }

  final DefaultHttpClient httpClient = new DefaultHttpClient(new BasicClientConnectionManager(registry));
  httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);

  return httpClient;
}
项目:XiaomiOrder    文件:MainActivity.java   
String get_url_contents( String url , List<NameValuePair> params , CookieStore cookieStore ) {
    try {
        HttpClient client = MySSLSocketFactory.createMyHttpClient();
        client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, USER_AGENT);
        HttpResponse response = null;
        if( cookieStore == null )
            response = client.execute( new HttpGet( params == null || params.size() == 0 ? url : url + "?" + URLEncodedUtils.format(params, "utf-8") ) );
        else {
            HttpContext mHttpContext = new BasicHttpContext();
            mHttpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
            response = client.execute( new HttpGet( params == null || params.size() == 0 ? url : url + "?" + URLEncodedUtils.format(params, "utf-8") ) , mHttpContext );
        }
        HttpEntity result = response.getEntity();
        if( result != null ) {
            InputStream mInputStream = result.getContent();
            String out = getStringFromInputStream(mInputStream);
            mInputStream.close();
            return out;
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return "";
}
项目:webpasser    文件:HttpclientUtil.java   
/**
 * 获取DefaultHttpClient实例
 *
 * @param charset
 * 参数编码集, 可空
 * @return DefaultHttpClient 对象
 */
@SuppressWarnings("deprecation")
private static DefaultHttpClient getDefaultHttpClient(final String charset){
    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1);
    //模拟浏览器,解决一些服务器程序只允许浏览器访问的问题
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)");
    httpclient.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE);
    httpclient.getParams().setParameter(CoreProtocolPNames.HTTP_CONTENT_CHARSET, charset == null ? CHARSET_GBK : charset);
    httpclient.setHttpRequestRetryHandler(requestRetryHandler);




    return httpclient;
}
项目:EinschlafenPodcastAndroidApp    文件:AntennapodHttpClient.java   
/**
 * Returns the HttpClient singleton.
 */
public static synchronized HttpClient getHttpClient() {
    if (httpClient == null) {
        if (AppConfig.DEBUG) Log.d(TAG, "Creating new instance of HTTP client");

        HttpParams params = new BasicHttpParams();
        params.setParameter(CoreProtocolPNames.USER_AGENT, AppPreferences.USER_AGENT);
        params.setIntParameter("http.protocol.max-redirects", MAX_REDIRECTS);
        params.setBooleanParameter("http.protocol.reject-relative-redirect",
                false);
        HttpConnectionParams.setSoTimeout(params, SOCKET_TIMEOUT);
        HttpConnectionParams.setConnectionTimeout(params, CONNECTION_TIMEOUT);
        HttpClientParams.setRedirecting(params, true);

        httpClient = new DefaultHttpClient(createClientConnectionManager(), params);
        // Workaround for broken URLs in redirection
        ((AbstractHttpClient) httpClient)
                .setRedirectHandler(new APRedirectHandler());
    }
    return httpClient;
}
项目:ZTLib    文件:RequestUserAgentHC4.java   
public void process(final HttpRequest request, final HttpContext context)
    throws HttpException, IOException {
    Args.notNull(request, "HTTP request");
    if (!request.containsHeader(HTTP.USER_AGENT)) {
        String s = null;
        final HttpParams params = request.getParams();
        if (params != null) {
            s = (String) params.getParameter(CoreProtocolPNames.USER_AGENT);
        }
        if (s == null) {
            s = this.userAgent;
        }
        if (s != null) {
            request.addHeader(HTTP.USER_AGENT, s);
        }
    }
}
项目:opennmszh    文件:HttpCollector.java   
private static HttpParams buildParams(final HttpCollectionSet collectionSet) {
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, computeVersion(collectionSet.getUriDef()));
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.parseInt(ParameterMap.getKeyedString(collectionSet.getParameters(), "timeout", DEFAULT_SO_TIMEOUT)));
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, Integer.parseInt(ParameterMap.getKeyedString(collectionSet.getParameters(), "timeout", DEFAULT_SO_TIMEOUT)));
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);

    //review the httpclient code, looks like virtual host is checked for null
    //and if true, sets Host to the connection's host property
    String virtualHost = collectionSet.getUriDef().getUrl().getVirtualHost();
    if (virtualHost != null) {
        params.setParameter(
                            ClientPNames.VIRTUAL_HOST, 
                            new HttpHost(virtualHost, collectionSet.getPort())
        );
    }

    return params;
}
项目:tag-augmented-reality-android    文件:Utilities.java   
public static String getHTTPResponse(String path) {

        String response = null;
        try {
            // source for http 1.1
            // http://stackoverflow.com/questions/3046424/http-post-requests-using-httpclient-take-2-seconds-why
            HttpParams params = new BasicHttpParams();
            params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
                    HttpVersion.HTTP_1_1);
            HttpClient client = new DefaultHttpClient(params);
            HttpGet get = new HttpGet(path);
            HttpResponse responseGet = client.execute(get);
            HttpEntity resEntity = responseGet.getEntity();
            response = EntityUtils.toString(resEntity, "utf-8").trim();
            return response;
        }// end try
        catch (Exception e) {
            e.printStackTrace();
            return null;
        }// end catch

    }
项目:ns-api    文件:NationStates.java   
private synchronized InputStream doRequest(String url) throws IOException {
    if (verbose) {
        System.out.println("Making HTTP request: " + url);
    }

    final HttpParams httpParams = new BasicHttpParams();
    HttpClient client = new DefaultHttpClient(httpParams);
    if (proxyIP != null) {
        HttpHost proxy = new HttpHost(proxyIP, proxyPort);
        client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, proxy);
    }
    HttpConnectionParams.setConnectionTimeout(client.getParams(), (int) timeout);
    HttpConnectionParams.setSoTimeout(client.getParams(), (int) timeout);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, this.userAgent);
    client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get);
    if (verbose) {
        System.out.println("Status code for request: " + response.getStatusLine().getStatusCode());
    }
    if (response.getStatusLine().getStatusCode() == 429)  {
        hardRateLimit = System.currentTimeMillis() + 900000L; //15 min
        throw new RateLimitReachedException();
    }
    return response.getEntity().getContent();
}
项目:phonty    文件:Contacts.java   
public Contacts(String url,Context _context) {
    context = _context;
    APIURL = url;
    httppost = new HttpPost(APIURL);
       httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\"");

       BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params,context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
       CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(Login.SESSION_COOKIE); 
    client.setCookieStore(cookieStore);
}
项目:phonty    文件:Calls.java   
public Calls(String url, Context _context) {
    context = _context;
    APIURL = url;
    httppost = new HttpPost(APIURL);
       httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\"");
       BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params,context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
    CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(Login.SESSION_COOKIE); 
    client.setCookieStore(cookieStore);
    VALUES = new ArrayList<CallItem>();
    type = "Calls:";

}
项目:phonty    文件:Rates.java   
public Rates(String url, Context _context) {
    context = _context;
    APIURL = url;
    httppost = new HttpPost(APIURL);
       httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\"");
       BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params,context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
    CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(Login.SESSION_COOKIE); 
    client.setCookieStore(cookieStore);
    VALUES = new ArrayList<PriceItem>();
    type = "Calls:";

}
项目:phonty    文件:Rates.java   
public void getsms(String country,String url) {
    APIURL = url;
    httppost = new HttpPost(APIURL);
       httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\"");
       BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params,context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
    type="SMS:";
    get(country);

}
项目:phonty    文件:Sms.java   
public Sms(String url,Context _context) {
    context = _context;
    APIURL = url;
    httppost = new HttpPost(APIURL);
       httppost.addHeader("Content-Type", "application/json; charset=\"utf-8\"");

       BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params,context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
       CookieStore cookieStore = new BasicCookieStore();
    cookieStore.addCookie(Login.SESSION_COOKIE); 
    client.setCookieStore(cookieStore);
}
项目:h2o-2    文件:GoogleAnalytics.java   
protected HttpClient createHttpClient(GoogleAnalyticsConfig config) {
  ThreadSafeClientConnManager connManager = new ThreadSafeClientConnManager();
  connManager.setDefaultMaxPerRoute(getDefaultMaxPerRoute(config));

  BasicHttpParams params = new BasicHttpParams();

  if (isNotEmpty(config.getUserAgent())) {
    params.setParameter(CoreProtocolPNames.USER_AGENT, config.getUserAgent());
  }

  if (isNotEmpty(config.getProxyHost())) {
    params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(config.getProxyHost(), config.getProxyPort()));
  }

  DefaultHttpClient client = new DefaultHttpClient(connManager, params);

  if (isNotEmpty(config.getProxyUserName())) {
    BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(new AuthScope(config.getProxyHost(), config.getProxyPort()),
            new UsernamePasswordCredentials(config.getProxyUserName(), config.getProxyPassword()));
    client.setCredentialsProvider(credentialsProvider);
  }

  return client;
}
项目:openhab1-addons    文件:HttpComponentsHelper.java   
/**
 * prepare for the https connection
 * call this in the constructor of the class that does the connection if
 * it's used multiple times
 */
private void setup() {
    SchemeRegistry schemeRegistry = new SchemeRegistry();

    // http scheme
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    // https scheme
    schemeRegistry.register(new Scheme("https", new EasySSLSocketFactory(), 443));

    params = new BasicHttpParams();
    params.setParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, 1);
    params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, new ConnPerRouteBean(1));
    params.setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, false);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    HttpProtocolParams.setContentCharset(params, "utf8");

    CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    // set the user credentials for our site "example.com"
    credentialsProvider.setCredentials(new AuthScope("example.com", AuthScope.ANY_PORT),
            new UsernamePasswordCredentials("UserNameHere", "UserPasswordHere"));
    clientConnectionManager = new ThreadSafeClientConnManager(params, schemeRegistry);

    context = new BasicHttpContext();
    context.setAttribute("http.auth.credentials-provider", credentialsProvider);
}
项目:CadalWorkspace    文件:Httpd.java   
public RequestListenerThread(int port, final String docroot) throws IOException {
    this.serversocket = new ServerSocket(port);
    this.params = new BasicHttpParams();
    this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 1000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = new BasicHttpProcessor();

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpFileHandler(docroot));

    // Set up the HTTP service
    this.httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    this.httpService.setParams(this.params);
    this.httpService.setHandlerResolver(reqistry);
}
项目:CadalWorkspace    文件:Httpd.java   
public RequestListenerThread(int port, final String docroot) throws IOException {
    this.serversocket = new ServerSocket(port);
    this.params = new BasicHttpParams();
    this.params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 1000).setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.STALE_CONNECTION_CHECK, false).setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true)
            .setParameter(CoreProtocolPNames.ORIGIN_SERVER, "HttpComponents/1.1");

    // Set up the HTTP protocol processor
    HttpProcessor httpproc = new BasicHttpProcessor();

    // Set up request handlers
    HttpRequestHandlerRegistry reqistry = new HttpRequestHandlerRegistry();
    reqistry.register("*", new HttpFileHandler(docroot));

    // Set up the HTTP service
    this.httpService = new HttpService(httpproc, new NoConnectionReuseStrategy(), new DefaultHttpResponseFactory());
    this.httpService.setParams(this.params);
    this.httpService.setHandlerResolver(reqistry);
}
项目:BigSemanticsJava    文件:HttpClientFactory.java   
public synchronized AbstractHttpClient create(String userAgent)
{
  if (userAgent == null)
  {
    userAgent = "";
  }
  // From Apache HttpClient doc: "HttpClient is fully thread-safe when used
  // with a thread-safe connection manager." The
  // PoolingClientConnectionManager we are using is such as thread-safe one.
  AbstractHttpClient client = new RedirectHttpClient(connectionManager);
  prepareHttpClient(client);
  if (userAgent.length() > 0)
  {
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
  }
  return client;
}
项目:OpenNMS    文件:HttpCollector.java   
private static HttpParams buildParams(final HttpCollectionSet collectionSet) {
    HttpParams params = new BasicHttpParams();
    params.setParameter(CoreProtocolPNames.PROTOCOL_VERSION, computeVersion(collectionSet.getUriDef()));
    params.setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, Integer.parseInt(ParameterMap.getKeyedString(collectionSet.getParameters(), "timeout", DEFAULT_SO_TIMEOUT)));
    params.setIntParameter(CoreConnectionPNames.SO_TIMEOUT, Integer.parseInt(ParameterMap.getKeyedString(collectionSet.getParameters(), "timeout", DEFAULT_SO_TIMEOUT)));
    params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);

    //review the httpclient code, looks like virtual host is checked for null
    //and if true, sets Host to the connection's host property
    String virtualHost = collectionSet.getUriDef().getUrl().getVirtualHost();
    if (virtualHost != null) {
        params.setParameter(
                            ClientPNames.VIRTUAL_HOST, 
                            new HttpHost(virtualHost, collectionSet.getPort())
        );
    }

    return params;
}
项目:transdroid-search    文件:RarbgAdapter.java   
@Override
public List<SearchResult> search(SharedPreferences prefs, String query, SortOrder order, int maxResults) throws Exception {

    if (httpclient == null) {
        httpclient = HttpHelper.buildDefaultSearchHttpClient(false);
        httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Torrent Search (by Transdroid) " + BuildConfig.VERSION_NAME);
    }
    if (accessToken == null) {
        requestAccessToken();
    }
    List<SearchResult> results = performSearch(query, order);

    if (results == null) {
        // Special case: our access token was invalid; request a new token and try again
        accessToken = null;
        requestAccessToken();
        results = performSearch(query, order);
        if (results == null)
            throw new IOException("RARBG returned a problem with out access token, even after requesting a new one and retrying");
    }

    return results;
}
项目:red5-mobileconsole    文件:HttpConnectionUtil.java   
/**
 * Returns a client with all our selected properties / params.
 * 
 * @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;
}