Exemple #1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public String call() throws java.io.IOException
            public override string call()
            {
                HttpPost request = new HttpPost(outerInstance.APP_BASE_PATH + FETCH_AND_LOCK_PATH);

                request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json");
                StringEntity stringEntity = new StringEntity("{ \"workerId\": \"aWorkerId\", \"asyncResponseTimeout\": 1000 }");

                request.Entity = stringEntity;

                CloseableHttpResponse response = httpClient.execute(request, HttpClientContext.create());
                string responseBody            = null;

                try
                {
                    HttpEntity entity = response.Entity;
                    responseBody = EntityUtils.ToString(entity);
                    request.releaseConnection();
                }
                finally
                {
                    response.close();
                }

                return(responseBody);
            }
Exemple #2
0
    public BeamHttpClient(BeamAPI beam, String httpUsername, String httpPassword, String oauthToken)
    {
        this.beam        = beam;
        this.cookieStore = new BasicCookieStore();

        if (httpUsername != null && httpPassword != null)
        {
            this.context = HttpClientContext.create();

            AuthCache ac = new BasicAuthCache();
            ac.put(new HttpHost(this.beam.basePath.getHost()), new BasicScheme());
            this.context.setAuthCache(ac);

            CredentialsProvider cp = new BasicCredentialsProvider();
            cp.setCredentials(
                AuthScope.ANY,
                new UsernamePasswordCredentials(httpUsername, httpPassword)
                );
            this.context.setCredentialsProvider(cp);
        }
        else
        {
            this.context = null;
        }

        this.http = this.buildHttpClient();

        if (oauthToken != null)
        {
            this.oauthToken = oauthToken;
        }
    }
Exemple #3
0
        protected HttpClient GetClient()
        {
            NetworkCredential   cred          = new NetworkCredential(UserName, Password);
            HttpClient          cli           = new HttpClient(MsgHandler());
            HttpHost            targetHost    = new HttpHost("localhost", 8080, "http");
            CredentialsProvider credsProvider = new BasicCredentialsProvider();

            credsProvider.setCredentials(AuthScope.ANY,
                                         new UsernamePasswordCredentials(DEFAULT_USER, DEFAULT_PASS));

            AuthCache authCache = new BasicAuthCache();

            authCache.put(targetHost, new BasicScheme());

            // Add AuthCache to the execution context
            final HttpClientContext context = HttpClientContext.create();

            context.setCredentialsProvider(credsProvider);
            context.setAuthCache(authCache);

            //WebRequest req = WebRequest.Create("http://" + Address.ToString() + "/en/" + f);
            //req.Credentials = new NetworkCredential(UserName, Password);
        }