當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。