当前位置: 首页>>代码示例>>Java>>正文


Java Request.Get方法代码示例

本文整理汇总了Java中org.apache.http.client.fluent.Request.Get方法的典型用法代码示例。如果您正苦于以下问题:Java Request.Get方法的具体用法?Java Request.Get怎么用?Java Request.Get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.fluent.Request的用法示例。


在下文中一共展示了Request.Get方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: execute

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
private <U> U execute(URISupplier<URI> uriSupplier, MappingFunction<byte[], U> responseMapper, Supplier<U> notFoundMapper) {
    try {
        URI uri = uriSupplier.get();
        Request request = Request.Get(uri);
        HttpResponse response = request.execute().returnResponse();

        if (response.getStatusLine().getStatusCode() == 200) {
            byte[] returnJson = EntityUtils.toByteArray(response.getEntity());

            return responseMapper.apply(returnJson);


        } else if (response.getStatusLine().getStatusCode() == 404) {
            return notFoundMapper.get();
        } else if (response.getStatusLine().getStatusCode() == 400) {
            throw new IllegalArgumentException("Bad Request");
        } else {
            throw new QueryExecutionException("Something went wrong, status code: " + response.getStatusLine().getStatusCode());
        }


    } catch (URISyntaxException | IOException e) {
        throw new ConnectionException("Error creating connection", e);
    }

}
 
开发者ID:ftrossbach,项目名称:kiqr,代码行数:27,代码来源:GenericBlockingRestKiqrClientImpl.java

示例2: getFile

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * 下载文件
 *
 * @param url URL
 * @return 文件的二进制流,客户端使用outputStream输出为文件
 */
public static byte[] getFile(String url) {
	try {
		Request request = Request.Get(url);
		HttpEntity resEntity = request.execute().returnResponse().getEntity();
		return EntityUtils.toByteArray(resEntity);
	} catch (Exception e) {
		logger.error("postFile请求异常," + e.getMessage() + "\n post url:" + url);
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:funtl,项目名称:framework,代码行数:18,代码来源:HttpUtils.java

示例3: get

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * 处理 GET 请求
 * @param url
 * @param query
 * @return
 */
public static String get(KeyPair keyPair, String url, Map<String,String> query) throws ApiException {
    URI uri = buildUri(url,query);
    if(uri == null) {
        return "";
    }
    url = uri.toString();
    log.info("get url:{}",url);

    Request request = Request.Get(url);

    return request(keyPair,request,Constant.METHOD_GET,query,"");
}
 
开发者ID:Liangdi,项目名称:zaoshu-java-sdk,代码行数:19,代码来源:HttpUtil.java

示例4: headers

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
public static Map<String,String> headers(KeyPair keyPair,String url) {
    Map<String,String> headerMap = new HashMap<>();
    URI uri = buildUri(url,null);
    if(uri == null) {
        return headerMap;
    }
    url = uri.toString();
    log.info("get url:{}",url);

    Request request = Request.Get(url);

    configRequest(request,Constant.METHOD_GET,keyPair,null,"");

    try {
        HttpResponse httpResponse = request.execute()
                .returnResponse();
        Header[] allHeaders = httpResponse.getAllHeaders();

        for (Header header :
                allHeaders) {
            headerMap.put(header.getName(),header.getValue());
        }
    } catch (IOException e) {
        e.printStackTrace();
    }


    return headerMap;
}
 
开发者ID:Liangdi,项目名称:zaoshu-java-sdk,代码行数:30,代码来源:HttpUtil.java

示例5: getFile

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * get下载文件
 *
 * @param url    请求地址
 * @param params 参数对象
 * @return 文件的二进制流
 */
public static InputStream getFile(String url, Object params) {
    StringBuilder requestURL = new StringBuilder(url);
    try {
        Request request = Request.Get(buildObjectParamURL(url, params));
        HttpEntity resEntity = request.execute().returnResponse().getEntity();
        logger.debug("http get file : {}", requestURL.toString());
        return resEntity.getContent();
    } catch (Exception e) {
        throw new RuntimeException("get请求失败", e);
    }
}
 
开发者ID:uncoseason,项目名称:wechatboot,代码行数:19,代码来源:Http.java

示例6: get

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * Send basic GET request with authorization header
 */
public Response get(String url, String auth) throws URISyntaxException, IOException {
	URI normUri = new URI(url).normalize();
	Request getRequest = Request.Get(normUri);
	if(StringUtil.isNotEmpty(auth)) {
		getRequest.addHeader("Authorization", auth);
	}
	Response response = executor.execute(getRequest);
	return response;
}
 
开发者ID:OpenNTF,项目名称:XPages-Fusion-Application,代码行数:13,代码来源:RestUtil.java

示例7: getTokenEntity

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
private static HttpEntity getTokenEntity(String category) throws Exception{
	String url = "";
	String username = "", password = "";
	if(category.equals(categorySTT)) {
		url = Configuration.TOKEN_API_URL + "?url=" + Configuration.getInstance().SPEECH_TO_TEXT_API_URL;
		username = Configuration.getInstance().SPEECH_TO_TEXT_USERNAME;
		password = Configuration.getInstance().SPEECH_TO_TEXT_PASSWORD;
	}
	else if(category.equals(categoryTTS)) {
		url = Configuration.TOKEN_API_URL + "?url=" + Configuration.getInstance().TEXT_TO_SPEECH_API_URL;
		username = Configuration.getInstance().TEXT_TO_SPEECH_USERNAME;
		password = Configuration.getInstance().TEXT_TO_SPEECH_PASSWORD;
	}

	System.out.println("url: "+url);

	if(url.length() > 0) {
		URI converseURI = new URI(url).normalize();
		Request request = Request.Get(converseURI);
		HttpResponse httpResponse = Utility.invokeRequest(request, username, password, url.startsWith("https"));
		if(httpResponse.getStatusLine().getStatusCode() == 200){
			HttpEntity entity = httpResponse.getEntity();
			return entity;
		}
	}
	throw new Exception("Invalid request URL");
}
 
开发者ID:CognitiveBuild,项目名称:Chatbot,代码行数:28,代码来源:Token.java

示例8: list

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
/**
 * List all secrets paths for given path.
 *
 * @param path location to list
 * @return list of nested paths
 * @throws IOException if the list operation failed to complete
 */
public Collection<String> list(String path) throws IOException {
    Request httpRequest = Request.Get(uriForPath(String.format("%s?list=true", path)));
    String responseContent = new ContentResponseHandler()
            .handleEntity(query("list", path, httpRequest, 200).getEntity())
            .asString();
    JSONObject data = new JSONObject(responseContent);

    ArrayList<String> secrets = new ArrayList<>();
    data.getJSONArray("array")
            .iterator()
            .forEachRemaining(secret -> secrets.add((String) secret));

    return secrets;
}
 
开发者ID:mesosphere,项目名称:dcos-commons,代码行数:22,代码来源:SecretsClient.java

示例9: buildAnnounceRequest

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
public Request buildAnnounceRequest(final URL trackerAnnounceURL, final RequestEvent event, final TorrentWithStats torrent, final ConnectionHandler connectionHandler) throws UnsupportedEncodingException {
    String emulatedClientQuery = this.getQuery()
            .replaceAll("\\{infohash}", urlEncoder.encode(new String(torrent.getTorrent().getInfoHash(), Torrent.BYTE_ENCODING)))
            .replaceAll("\\{uploaded}", String.valueOf(torrent.getUploaded()))
            .replaceAll("\\{downloaded}", String.valueOf(torrent.getDownloaded()))
            .replaceAll("\\{left}", String.valueOf(torrent.getLeft()))
            .replaceAll("\\{port}", String.valueOf(connectionHandler.getPort()))
            .replaceAll("\\{numwant}", String.valueOf(this.getNumwant(event)));

    if (this.peerIdGenerator.getShouldUrlEncoded()) {
        emulatedClientQuery = emulatedClientQuery.replaceAll("\\{peerid}", urlEncoder.encode(this.getPeerId(torrent.getTorrent(), event)));
    } else {
        emulatedClientQuery = emulatedClientQuery.replaceAll("\\{peerid}", this.getPeerId(torrent.getTorrent(), event));
    }

    // set ip or ipv6 then remove placeholders that were left empty
    if (connectionHandler.getIpAddress() instanceof Inet4Address) {
        emulatedClientQuery = emulatedClientQuery.replaceAll("\\{ip}", connectionHandler.getIpAddress().getHostAddress());
    } else if(connectionHandler.getIpAddress() instanceof Inet6Address) {
        emulatedClientQuery = emulatedClientQuery.replaceAll("\\{ipv6}", urlEncoder.encode(connectionHandler.getIpAddress().getHostAddress()));
    }
    emulatedClientQuery = emulatedClientQuery.replaceAll("[&]*[a-zA-Z0-9]+=\\{ipv6}", "");
    emulatedClientQuery = emulatedClientQuery.replaceAll("[&]*[a-zA-Z0-9]+=\\{ip}", "");

    if (event == null || event == RequestEvent.NONE) {
        // if event was NONE, remove the event from the query string
        emulatedClientQuery = emulatedClientQuery.replaceAll("([&]*[a-zA-Z0-9]+=\\{event})", "");
    } else {
        emulatedClientQuery = emulatedClientQuery.replaceAll("\\{event}", event.getEventName());
    }

    if (emulatedClientQuery.contains("{key}")) {
        final String key = getKey(torrent.getTorrent(), event).orElseThrow(() -> new IllegalStateException("Client request query contains 'key' but BitTorrentClient does not have a key."));
        emulatedClientQuery = emulatedClientQuery.replaceAll("\\{key}", urlEncoder.encode(key));
    }

    final Matcher matcher = Pattern.compile("(\\{.*?})").matcher(emulatedClientQuery);
    if (matcher.find()) {
        final String unrecognizedPlaceHolder = matcher.group();
        throw new UnrecognizedAnnounceParameter("Placeholder " + unrecognizedPlaceHolder + " were not recognized while building announce URL.");
    }

    // Append ? or & only if query contains params
    final String base;
    if (emulatedClientQuery.length() > 0) {
        base = trackerAnnounceURL.toString() + (trackerAnnounceURL.toString().contains("?") ? "&" : "?");
    } else {
        base = trackerAnnounceURL.toString();
    }
    final String url = base + emulatedClientQuery;



    final Request request = Request.Get(url);
    this.addHeadersToRequest(request, trackerAnnounceURL);

    return request;
}
 
开发者ID:anthonyraymond,项目名称:joal,代码行数:59,代码来源:BitTorrentClient.java

示例10: get

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
protected Request get(String path) {
    return Request.Get(url + path);
}
 
开发者ID:Roboroxx,项目名称:itunesconnect-api,代码行数:4,代码来源:AbstractAppleApi.java

示例11: get

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
private Response get(HttpRequest request) throws IOException {
    Request apacheRequest = Request.Get(request.getUrl());
    prepareRequest(apacheRequest);
    return apacheRequest.execute();
}
 
开发者ID:DorsetProject,项目名称:dorset-framework,代码行数:6,代码来源:ApacheHttpClient.java

示例12: getPage

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
static String getPage(String targetURL) throws Exception {
    Request x = Request.Get(targetURL);
    Response y = x.execute();
    Content z = y.returnContent();
    return z.toString();
}
 
开发者ID:palette-software,项目名称:pet-restart,代码行数:7,代码来源:HelperHttpClient.java

示例13: get

import org.apache.http.client.fluent.Request; //导入方法依赖的package包/类
HttpClientResponseDTO get(final HttpClientCallDTO reqDto) throws IOException {

        final Request request = Request.Get(reqDto.getUrl());

        return executeRequest(request, reqDto.getHeaders());
    }
 
开发者ID:mgtechsoftware,项目名称:smockin,代码行数:7,代码来源:HttpClientServiceImpl.java


注:本文中的org.apache.http.client.fluent.Request.Get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。