當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpUriRequest類代碼示例

本文整理匯總了Java中org.apache.http.client.methods.HttpUriRequest的典型用法代碼示例。如果您正苦於以下問題:Java HttpUriRequest類的具體用法?Java HttpUriRequest怎麽用?Java HttpUriRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


HttpUriRequest類屬於org.apache.http.client.methods包,在下文中一共展示了HttpUriRequest類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute0

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
private static String execute0(HttpUriRequest httpUriRequest) throws Exception {
    CloseableHttpResponse closeableHttpResponse = null;

    String var4;
    try {
        closeableHttpResponse = closeableHttpClient.execute(httpUriRequest);
        String response = EntityUtils.toString(closeableHttpResponse.getEntity(), CHARSET);
        var4 = response;
    } catch (Exception var7) {
        throw var7;
    } finally {
        CloseUtils.close(closeableHttpResponse);
    }

    return var4;
}
 
開發者ID:wxz1211,項目名稱:dooo,代碼行數:17,代碼來源:OpenClient.java

示例2: getModSlug0

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
@Nullable
private String getModSlug0(int id)
{
    try
    {
        log.debug("Getting mod slug from server...");
        URI uri = getURI(CURSEFORGE_URL, String.format(PROJECT_PATH, id), null);
        HttpGet request = new HttpGet(uri.toURL().toString());
        HttpContext context = new BasicHttpContext();
        HttpResponse response = http.execute(request, context);
        EntityUtils.consume(response.getEntity());
        HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
        HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
        String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
        Splitter splitter = Splitter.on('/').omitEmptyStrings();
        List<String> pathParts = splitter.splitToList(currentUrl);
        return pathParts.get(pathParts.size() - 1);
    }
    catch (Exception e)
    {
        log.error("Failed to perform request from CurseForge site.", e);
        return null;
    }
}
 
開發者ID:PaleoCrafter,項目名稱:CurseSync,代碼行數:25,代碼來源:CurseAPI.java

示例3: execute

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
public <T> Response<T> execute() {
    HttpProxy httpProxy = getHttpProxyFromPool();
    CookieStore cookieStore = getCookieStoreFromPool();

    CloseableHttpClient httpClient = httpClientPool.getHttpClient(siteConfig, request);
    HttpUriRequest httpRequest = httpClientPool.createHttpUriRequest(siteConfig, request, createHttpHost(httpProxy));
    CloseableHttpResponse httpResponse = null;
    IOException executeException = null;
    try {
        HttpContext httpContext = createHttpContext(httpProxy, cookieStore);
        httpResponse = httpClient.execute(httpRequest, httpContext);
    } catch (IOException e) {
        executeException = e;
    }

    Response<T> response = ResponseFactory.createResponse(
            request.getResponseType(), siteConfig.getCharset(request.getUrl()));

    response.handleHttpResponse(httpResponse, executeException);

    return response;
}
 
開發者ID:brucezee,項目名稱:jspider,代碼行數:23,代碼來源:HttpClientExecutor.java

示例4: execute

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
/**
 * Wraps an HttpClient.execute() to manage the authorization headers.
 * This will add the proper Authorization header, and retry if the
 * auth token has expired.
 */
@Override
public HttpResponse execute(HttpUriRequest request)
    throws ClientProtocolException, IOException {
  initialize();
  addGoogleAuthHeader(request, authToken);
  HttpResponse response = client.execute(request);
  if (response.getStatusLine().getStatusCode() == 401) {
    Log.i(LOG_TAG, "Invalid token: " + authToken);
    accountManager.invalidateAuthToken(ACCOUNT_TYPE, authToken);
    authToken = getAuthToken();
    removeGoogleAuthHeaders(request);
    addGoogleAuthHeader(request, authToken);
    Log.i(LOG_TAG, "new token: " + authToken);
    response = client.execute(request);
  }
  return response;
}
 
開發者ID:mit-cml,項目名稱:appinventor-extensions,代碼行數:23,代碼來源:ClientLoginHelper.java

示例5: rawGet

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
public void rawGet(String str, RawNetworkCallback rawNetworkCallback) throws Throwable {
    HttpUriRequest httpGet = new HttpGet(str);
    HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
            DefaultHttpClient();
    HttpResponse execute = sSLHttpClient.execute(httpGet);
    int statusCode = execute.getStatusLine().getStatusCode();
    if (statusCode == 200) {
        if (rawNetworkCallback != null) {
            rawNetworkCallback.onResponse(execute.getEntity().getContent());
        }
        sSLHttpClient.getConnectionManager().shutdown();
        return;
    }
    String entityUtils = EntityUtils.toString(execute.getEntity(), Constants.UTF_8);
    HashMap hashMap = new HashMap();
    hashMap.put("error", entityUtils);
    hashMap.put("status", Integer.valueOf(statusCode));
    sSLHttpClient.getConnectionManager().shutdown();
    throw new Throwable(new Hashon().fromHashMap(hashMap));
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:21,代碼來源:NetworkHelper.java

示例6: getModpack0

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
@Nullable
private CurseProject getModpack0(@Nonnull String slug)
{
    try
    {
        log.debug("Getting modpack from server...");
        URI uri = getURI(MCF_URL, String.format(PACK_PATH, slug), null);
        HttpUriRequest request = new HttpGet(uri.toURL().toString());
        HttpResponse response = http.execute(request);
        String json = EntityUtils.toString(response.getEntity());
        return GSON.fromJson(json, CurseProject.class);
    }
    catch (Exception e)
    {
        log.error("Failed to perform request from MCF Widget API.", e);
        return null;
    }
}
 
開發者ID:PaleoCrafter,項目名稱:CurseSync,代碼行數:19,代碼來源:CurseAPI.java

示例7: determineProxy

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
@Override
public Proxy determineProxy(HttpHost host, HttpRequest request, HttpContext context, IPPool ipPool,
        CrawlerSession crawlerSession) {
    HttpClientContext httpClientContext = HttpClientContext.adapt(context);

    Proxy proxy = (Proxy) crawlerSession.getExtInfo(VSCRAWLER_AVPROXY_KEY);
    if (proxy == null) {
        String accessUrl = null;
        if (request instanceof HttpRequestWrapper || request instanceof HttpGet) {
            accessUrl = HttpUriRequest.class.cast(request).getURI().toString();
        }
        if (!PoolUtil.isDungProxyEnabled(httpClientContext)) {
            log.info("{}不會被代理", accessUrl);
            return null;
        }
        proxy = ipPool.getIP(host.getHostName(), accessUrl);
        if (proxy == null) {
            return null;
        }
        crawlerSession.setExtInfo(VSCRAWLER_AVPROXY_KEY, proxy);
    }

    return proxy;
}
 
開發者ID:virjar,項目名稱:vscrawler,代碼行數:25,代碼來源:EverySessionPlanner.java

示例8: getConfFromHadoop

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
/**
 * Get the job conf from hadoop name node
 * @param hadoopJobId
 * @return the lineage info
 * @throws java.io.IOException
 */
public String getConfFromHadoop(String hadoopJobId)
  throws Exception {
  String url = this.serverURL + "/" + hadoopJobId + "/conf";
  logger.debug("get job conf from : {}", url);
  HttpUriRequest request = new HttpGet(url);
  HttpResponse response = httpClient.execute(request);
  HttpEntity entity = response.getEntity();
  String confResult = EntityUtils.toString(entity);
  EntityUtils.consume(entity);
  return confResult;
}
 
開發者ID:thomas-young-2013,項目名稱:wherehowsX,代碼行數:18,代碼來源:HadoopJobHistoryNodeExtractor.java

示例9: HttpClient

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
public HttpClient(final Console console) {
    this.credentials = new HashMap<String, Credentials>();
    this.request = new AtomicReference<>();

    this.baseUrl = new Supplier<String>() {
        @Override
        public String get(Set<Hint> hints) {
            return console.getBaseUrl();
        }
    };

    this.httpClient = createHttpClient();
    this.httpClientContext = createHttpClientContext(console);

    console.onInterrupt(new Runnable() {
        @Override
        public void run() {
            HttpUriRequest req = request.get();
            if (req != null) {
                req.abort();
            }
        }
    });
}
 
開發者ID:pascalgn,項目名稱:jiracli,代碼行數:25,代碼來源:HttpClient.java

示例10: constructRequest

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
private HttpUriRequest constructRequest(byte[] pduBytes, boolean useProxy)
    throws IOException
{
  try {
    HttpPostHC4 request = new HttpPostHC4(apn.getMmsc());
    for (Header header : getBaseHeaders()) {
      request.addHeader(header);
    }

    request.setEntity(new ByteArrayEntityHC4(pduBytes));
    if (useProxy) {
      HttpHost proxy = new HttpHost(apn.getProxy(), apn.getPort());
      request.setConfig(RequestConfig.custom().setProxy(proxy).build());
    }
    return request;
  } catch (IllegalArgumentException iae) {
    throw new IOException(iae);
  }
}
 
開發者ID:XecureIT,項目名稱:PeSanKita-android,代碼行數:20,代碼來源:OutgoingLegacyMmsConnection.java

示例11: logRequest

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
void logRequest(String serviceName, HttpUriRequest request) throws IOException {
    System.setProperty("org.apache.commons.logging.Log","org.apache.commons.logging.impl.SimpleLog");
    System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
    System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.wire", "DEBUG");
    CloseableHttpClient httpClient = signingClientForServiceName(serviceName);
    try (CloseableHttpResponse response = httpClient.execute(request)) {
        System.out.println(response.getStatusLine());
        String inputLine ;
        BufferedReader br = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
        try {
            while ((inputLine = br.readLine()) != null) {
                System.out.println(inputLine);
            }
            br.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
開發者ID:awslabs,項目名稱:aws-request-signing-apache-interceptor,代碼行數:20,代碼來源:Sample.java

示例12: c

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
private HttpUriRequest c() {
    if (this.f != null) {
        return this.f;
    }
    if (this.j == null) {
        byte[] b = this.c.b();
        CharSequence b2 = this.c.b(AsyncHttpClient.ENCODING_GZIP);
        if (b != null) {
            if (TextUtils.equals(b2, "true")) {
                this.j = b.a(b);
            } else {
                this.j = new ByteArrayEntity(b);
            }
            this.j.setContentType(this.c.c());
        }
    }
    HttpEntity httpEntity = this.j;
    if (httpEntity != null) {
        HttpUriRequest httpPost = new HttpPost(b());
        httpPost.setEntity(httpEntity);
        this.f = httpPost;
    } else {
        this.f = new HttpGet(b());
    }
    return this.f;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:27,代碼來源:q.java

示例13: authenticate

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
@Override
public BackendAuthResult authenticate(_MatrixID mxid, String password) {
    RestAuthRequestJson auth = new RestAuthRequestJson();
    auth.setMxid(mxid.getId());
    auth.setLocalpart(mxid.getLocalPart());
    auth.setDomain(mxid.getDomain());
    auth.setPassword(password);

    HttpUriRequest req = RestClientUtils.post(cfg.getEndpoints().getAuth(), gson, "auth", auth);
    try (CloseableHttpResponse res = client.execute(req)) {
        int status = res.getStatusLine().getStatusCode();
        if (status < 200 || status >= 300) {
            return BackendAuthResult.failure();
        }

        return parser.parse(res, "auth", BackendAuthResult.class);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:kamax-io,項目名稱:mxisd,代碼行數:21,代碼來源:RestAuthProvider.java

示例14: args

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
/**
 * 攔截HttpClient的Post與Get方法.
 * 
 */
@Around("execution(* org.apache.http.client.HttpClient.execute(..)) && args(httpUriRequest)")
public Object around(final ProceedingJoinPoint proceedingJoinPoint, final HttpUriRequest httpUriRequest)
    throws Throwable {
  final long startTime = System.currentTimeMillis();
  final Object[] args = proceedingJoinPoint.getArgs();
  final Object result = proceedingJoinPoint.proceed(args);

  if (httpUriRequest instanceof HttpUriRequest) {
    final String methodName = httpUriRequest.getMethod();
    final String className = httpUriRequest.getURI().toString();

    Tracer.getInstance().addBinaryAnnotation(className, methodName, (int) (System.currentTimeMillis() - startTime));
  }

  return result;
}
 
開發者ID:junzixiehui,項目名稱:godeye,代碼行數:21,代碼來源:HttpClientAop.java

示例15: getResponseInternal0

import org.apache.http.client.methods.HttpUriRequest; //導入依賴的package包/類
private String getResponseInternal0(String baseUrl, String resourcePath) throws UnsupportedOperationException, IOException {
	CloseableHttpResponse response = null;
	String json = "";
	try {
		HttpUriRequest request = new HttpGet(new URI(baseUrl + "/" + resourcePath));
		response = client.execute(request);
		json = IOUtils.toString(response.getEntity().getContent());
	} catch(Exception e) {
		LOGGER.error("Failed to execute request {} : {}",resourcePath,e);
	} finally {
		if(response != null) response.close();
	}	
	return json;
}
 
開發者ID:cool-mist,項目名稱:DiscordConvenienceBot,代碼行數:15,代碼來源:SteamClient.java


注:本文中的org.apache.http.client.methods.HttpUriRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。