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


Java HttpGet.setURI方法代码示例

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


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

示例1: getSubscriptions

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
/**
 * Gets a list of {@link Subscription}s that the current user is subscribed
 * to.
 * 
 * @return {@link List}<{@link Subscription}> representing the subscriptions
 * @throws URISyntaxException
 * @throws IOException
 * @throws GroupsIOApiException
 */
public List<Subscription> getSubscriptions() throws URISyntaxException, IOException, GroupsIOApiException
{
    final URIBuilder uri = new URIBuilder().setPath(baseUrl + "getsubs");
    uri.setParameter("limit", MAX_RESULTS);
    final HttpGet request = new HttpGet();
    request.setURI(uri.build());
    
    Page page = callApi(request, Page.class);
    
    final List<Subscription> subscriptions = Arrays.asList(OM.convertValue(page.getData(), Subscription[].class));
    
    while (page.getHasMore())
    {
        uri.setParameter("page_token", page.getNextPageToken().toString());
        request.setURI(uri.build());
        page = callApi(request, Page.class);
        subscriptions.addAll(Arrays.asList(OM.convertValue(page.getData(), Subscription[].class)));
    }
    
    return subscriptions;
}
 
开发者ID:lake54,项目名称:groupsio-api-java,代码行数:31,代码来源:UserResource.java

示例2: getGetResponse

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
private CloseableHttpResponse getGetResponse(String apiUrl, HttpGet httpGet) throws IllegalStateException {
	localContext.setCookieStore(cookieStore);
	try {
		httpGet.setURI(new URI(apiUrl));
		if (reqHeader != null) {
			Iterator<String> iterator = reqHeader.keySet().iterator();
			while (iterator.hasNext()) {
				String key = iterator.next();
				httpGet.addHeader(key, reqHeader.get(key));
			}
		}
		return httpclient.execute(httpGet, localContext);
	} catch (Exception e) {
		throw new IllegalStateException(e);
	}
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:17,代码来源:HttpCallImpl.java

示例3: doInBackground

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
@Override
protected Integer doInBackground(Context... params) {

    HttpResponse response;
    try {
        LocationManager lm = (LocationManager) params[0].getSystemService(Context.LOCATION_SERVICE);
        Criteria crit = new Criteria();
        crit.setAccuracy(Criteria.ACCURACY_FINE);
        String provider = lm.getBestProvider(crit, true);

        Location loc = lm.getLastKnownLocation(provider);

        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet();

        request.setURI(new URI(Utils.WEATHER_URL + "lat=" +
                loc.getLatitude() +
                "&lon=" +
                +loc.getLongitude()
                + "&units=metric"));

        response = client.execute(request);
        String result = EntityUtils.toString(response.getEntity());
        JSONObject jsonResponse = new JSONObject(result);
        JSONObject jsonWeather = jsonResponse.getJSONObject("main");
        return jsonWeather.getInt("temp");

    } catch (Exception e) {
        error = e;
    }
    return 0;
}
 
开发者ID:feup-infolab,项目名称:labtablet,代码行数:33,代码来源:AsyncWeatherFetcher.java

示例4: getSubscription

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
/**
 * Gets a user's {@link Subscription} for the specified group ID
 * 
 * @return the user's {@link Subscription} for the specified group ID
 * @throws URISyntaxException
 * @throws IOException
 * @throws GroupsIOApiException
 */
public Subscription getSubscription(final Integer groupId) throws URISyntaxException, IOException, GroupsIOApiException
{
    final URIBuilder uri = new URIBuilder().setPath(baseUrl + "getsub");
    uri.setParameter("group_id", groupId.toString());
    final HttpGet request = new HttpGet();
    request.setURI(uri.build());
    
    return callApi(request, Subscription.class);
}
 
开发者ID:lake54,项目名称:groupsio-api-java,代码行数:18,代码来源:UserResource.java

示例5: responseContent

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
public static String responseContent(String url) throws Exception {
	HttpClient client = new DefaultHttpClient();
	HttpGet request = new HttpGet();
	request.setURI(new URI(url));
	InputStream is = client.execute(request).getEntity().getContent();
	BufferedReader inb = new BufferedReader(new InputStreamReader(is));
	StringBuilder sb = new StringBuilder("");
	String line;
	String NL = System.getProperty("line.separator");
	while ((line = inb.readLine()) != null) {
		sb.append(line).append(NL);
	}
	inb.close();
	return sb.toString();
}
 
开发者ID:Suhas010,项目名称:Artificial-Intelligent-chat-bot-,代码行数:16,代码来源:NetworkUtils.java

示例6: getGetResponse

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
private HttpResponse getGetResponse(String apiUrl, HttpGet httpGet) throws IOException {
	try{
		httpGet.setURI(new URI(apiUrl));
		if(reqHeader != null) {
			Iterator<String> iterator = reqHeader.keySet().iterator();
			while(iterator.hasNext()) {
				String key = iterator.next();
				httpGet.addHeader(key, reqHeader.get(key));
			}
		}
		return httpClient.execute(httpGet);
	}catch(Exception e){
    	throw new IllegalStateException(e);
    }
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:16,代码来源:HttpCallSSL.java

示例7: doGet

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
/**
 * Executes get http request to an endpoint with provided headers.
 *
 * @param uri
 *            Endpoint that needs to be hit
 * @param headers
 *            Key value pair of headers
 * @return Return response body after executing GET
 * @throws StockException
 *             if api doesn't return with success code or when null/empty
 *             endpoint is passed in uri
 */
public static String doGet(final String uri,
        final Map<String, String> headers) throws StockException {

    if (sHttpClient == null) {
        sHttpClient = HttpUtils.initialize();
    }

    HttpResponse response = null;
    String responseBody = null;
    HttpGet request = new HttpGet();

    if (uri == null || uri.isEmpty()) {
        throw new StockException(-1, "URI cannot be null or Empty");
    }

    if (headers != null) {
        for (Entry<String, String> entry : headers.entrySet()) {
            request.setHeader(entry.getKey(), entry.getValue());
        }
    }

    try {
        request.setURI(new URI(uri));
        response = sHttpClient.execute(request);
        if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
            responseBody = EntityUtils.toString(response.getEntity());
        } else if (response.getStatusLine().getStatusCode()
                == HttpStatus.SC_NO_CONTENT) {
            responseBody = String.valueOf(HttpStatus.SC_NO_CONTENT);
        } else if (response.getStatusLine().getStatusCode()
                / HTTP_STATUS_CODE_DIVISOR
                    == HTTP_STATUS_CODE_API_ERROR) {
            responseBody = EntityUtils.toString(response.getEntity());
            throw new StockException(response.getStatusLine()
                    .getStatusCode(), responseBody);
        } else if (response.getStatusLine().getStatusCode()
                / HTTP_STATUS_CODE_DIVISOR == HTTP_STATUS_CODE_REDIRECT) {
            String locationHeader =
                    response.getHeaders("Location")[0].getValue();
            responseBody = locationHeader;
        } else if (response.getStatusLine().getStatusCode()
                / HTTP_STATUS_CODE_DIVISOR
                    == HTTP_STATUS_CODE_SERVER_ERROR) {
            throw new StockException(response.getStatusLine()
                    .getStatusCode(), "API returned with Server Error");

        }

    } catch (StockException se) {
        throw se;
    } catch (Exception ex) {
        throw new StockException(ex.getMessage());
    }

    return responseBody;
}
 
开发者ID:adobe,项目名称:stock-api-sdk,代码行数:69,代码来源:ApiUtils.java

示例8: get

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
/**
 * Retorna o extrato de transações da Conta Digital em formato JSON ou CNAB 240 [Desabilitado]
 * @param dataInicio: Data de início do extrato desejado
 * @param dataFim: Data de fim do extrato desejado
 * @param formato: Formato de extrato desejado (JSON ou CNAB 240 [Desabilitado])
 * @return List<TransacaoExtrato>
 */
public List<TransacaoExtrato> get(Date dataInicio, Date dataFim, FormatoExtrato formato) throws IOException, ParseException, URISyntaxException, PJBankException {
    PJBankClient client = new PJBankClient(this.endPoint.concat("/transacoes"));
    HttpGet httpGet = client.getHttpGetClient();
    httpGet.addHeader("x-chave-conta", this.chave);

    if (!formato.equals(FormatoExtrato.JSON))
        httpGet.removeHeaders("Accept");

    URIBuilder uriBuilder = new URIBuilder(httpGet.getURI());
    DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

    uriBuilder.addParameter("data_inicio", dateFormat.format(dataInicio));
    uriBuilder.addParameter("data_fim", dateFormat.format(dataFim));
    uriBuilder.addParameter("formato", formato.getName());

    httpGet.setURI(uriBuilder.build());

    String response = EntityUtils.toString(client.doRequest(httpGet).getEntity());

    JSONArray responseArray = new JSONArray(response);
    List<TransacaoExtrato> transacoesExtrato = new ArrayList<>();

    for(int i = 0; i < responseArray.length(); i++) {
        JSONObject responseObject = (JSONObject) responseArray.get(i);

        TransacaoExtrato transacaoExtrato = new TransacaoExtrato();
        transacaoExtrato.setIdTransacao(responseObject.getString("id_operacao"));
        transacaoExtrato.setIdentificador(responseObject.getString("identificador"));
        transacaoExtrato.setNomeFavorecido(responseObject.getString("nome_favorecido"));
        transacaoExtrato.setCnpjFavorecido(responseObject.getString("cnpj_favorecido"));
        transacaoExtrato.setDataPagamento(dateFormat.parse(responseObject.getString("data_pagamento")));
        transacaoExtrato.setValor(responseObject.getDouble("valor"));
        transacaoExtrato.setHistorico(responseObject.getString("historico"));
        transacaoExtrato.setTipo(TipoTransacao.fromString(responseObject.getString("tipo_transacao")));

        transacoesExtrato.add(transacaoExtrato);
    }

    return transacoesExtrato;
}
 
开发者ID:pjbank,项目名称:pjbank-java-sdk,代码行数:48,代码来源:ContaDigitalManager.java

示例9: getTransactionFiles

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
/**
 * Retorna a lista de anexos de uma transação com ou sem filtro de tipo
 * @param idTransacao: Código da transação à ser consultada
 * @param tipoAnexo: Tipo de anexo à ser retornado
 * @return boolean
 */
public List<AnexoTransacao> getTransactionFiles(String idTransacao, TipoAnexo tipoAnexo) throws IOException,
        URISyntaxException, ParseException, PJBankException {
    PJBankClient client = new PJBankClient(this.endPoint.concat("/transacoes/").concat(idTransacao).concat("/documentos"));
    HttpGet httpGet = client.getHttpGetClient();
    httpGet.addHeader("x-chave-conta", this.chave);

    if (tipoAnexo != null) {
        URIBuilder uriBuilder = new URIBuilder(httpGet.getURI());

        uriBuilder.addParameter("tipo", tipoAnexo.getName());

        httpGet.setURI(uriBuilder.build());
    }

    String response = EntityUtils.toString(client.doRequest(httpGet).getEntity());

    List<AnexoTransacao> anexosTransacao = new ArrayList<>();

    if(response.trim().charAt(0) == '{') {
        JSONObject responseObject = new JSONObject(response);
        if (responseObject.has("status") && responseObject.getString("status").equals("404")) {
            return anexosTransacao;
        }
    } else {

        JSONArray responseArray = new JSONArray(response);
        DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");

        for (int i = 0; i < responseArray.length(); i++) {
            JSONObject object = (JSONObject) responseArray.get(i);

            AnexoTransacao anexoTransacao = new AnexoTransacao();
            anexoTransacao.setUrl(object.getString("imagem"));
            anexoTransacao.setTipo(TipoAnexo.fromString(object.getString("tipo")));
            anexoTransacao.setNome(object.getString("nome"));
            anexoTransacao.setFormato(FormatoArquivo.fromString(object.getString("formato")));
            anexoTransacao.setTamanho(object.getLong("tamanho"));
            anexoTransacao.setData(dateFormat.parse(object.getString("data")));

            anexosTransacao.add(anexoTransacao);
        }
    }

    return anexosTransacao;
}
 
开发者ID:pjbank,项目名称:pjbank-java-sdk,代码行数:52,代码来源:ContaDigitalManager.java

示例10: settingRequest

import org.apache.http.client.methods.HttpGet; //导入方法依赖的package包/类
private void settingRequest() {
	URI uri = null;
	if (uriBuilder != null && uriBuilder.getQueryParams().size() != 0) {
		try {
			uri = uriBuilder.setPath(request.getURI().toString()).build();
		} catch (URISyntaxException e) {
			logger.warn(e.getMessage(), e);
		}
	}

	HttpEntity httpEntity = null;

	switch (type) {
	case 1:
		httpEntity = builder.build();
		if (httpEntity.getContentLength() > 0)
			((HttpPost) request).setEntity(builder.build());
		break;

	case 2:
		HttpGet get = ((HttpGet) request);
		if (uri != null)
			get.setURI(uri);
		break;

	case 3:
		httpEntity = builder.build();
		if (httpEntity.getContentLength() > 0)
			((HttpPut) request).setEntity(httpEntity);
		break;

	case 4:
		HttpDelete delete = ((HttpDelete) request);
		if (uri != null)
			delete.setURI(uri);

		break;
	}

	if (isHttps && socketFactory != null) {
		clientBuilder.setSSLSocketFactory(socketFactory);

	} else if (isHttps) {
		clientBuilder.setSSLSocketFactory(getSSLSocketFactory());
	}

	clientBuilder.setDefaultCookieStore(cookieStore);
	request.setConfig(config.build());
}
 
开发者ID:swxiao,项目名称:bubble2,代码行数:50,代码来源:HttpUtils.java


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