Java Code Examples for org.apache.http.HttpHost#DEFAULT_SCHEME_NAME

The following examples show how to use org.apache.http.HttpHost#DEFAULT_SCHEME_NAME . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpFluentService.java    From AthenaServing with Apache License 2.0 5 votes vote down vote up
/**
 * 设置代理
 * @param request
 * @param hostName
 * @param port
 * @param schemeName
 * @return
 */
private Request buildProxy(Request request, String hostName, Integer port, String schemeName) {
    if(StringUtils.isNotEmpty(hostName) && port != null) {
        //设置代理
        if (StringUtils.isEmpty(schemeName)) {
            schemeName = HttpHost.DEFAULT_SCHEME_NAME;
        }
        request.viaProxy(new HttpHost(hostName, port, schemeName));
    }
    return request;
}
 
Example 2
Source File: TestHttpClientService.java    From jframe with Apache License 2.0 5 votes vote down vote up
public void testJson() {
    try {
        CloseableHttpClient httpClient = HttpClients.createDefault();

        HttpHost target = new HttpHost("120.27.182.142", 80, HttpHost.DEFAULT_SCHEME_NAME);
        HttpRequestBase request = new HttpPost(target.toURI() + "/mry/usr/qryusr");
        request.addHeader("Api-Token", "76067");

        String data = "";
        // ((HttpPost) request).setEntity(new StringEntity(data,
        // ContentType.create("text/plain", "utf-8")));

        CloseableHttpResponse resp = httpClient.execute(request);
        HttpEntity entity = resp.getEntity();

        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        InputStream is = entity.getContent();
        byte[] buf = new byte[32];
        int len = 0;
        while ((len = is.read(buf)) != -1) {
            baos.write(buf, 0, len);
        }
        String str = new String(baos.toByteArray(), "utf-8");
        for (byte b : baos.toByteArray()) {
            System.out.print(b);
            System.out.print(' ');
        }

        Reader reader = new InputStreamReader(entity.getContent(), ContentType.getOrDefault(entity).getCharset());
        // TODO decode by mime-type

        Map<String, String> rspMap = GSON.fromJson(reader, HashMap.class);
        String usrJson = rspMap.get("usr");
        Map<String, Object> usr = GSON.fromJson(usrJson, HashMap.class);
        System.out.println(usr.get("id").toString() + usr.get("name"));
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
Example 3
Source File: HTTPAuthUtil.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
static public HttpHost authscopeToHost(AuthScope scope) {
  return new HttpHost(scope.getHost(), scope.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
}
 
Example 4
Source File: HTTPFactory.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
@Deprecated
public static HTTPSession newSession(AuthScope scope) throws HTTPException {
  HttpHost hh = new HttpHost(scope.getHost(), scope.getPort(), HttpHost.DEFAULT_SCHEME_NAME);
  return new HTTPSession(hh);
}