本文整理匯總了Java中org.apache.http.client.methods.RequestBuilder.addParameter方法的典型用法代碼示例。如果您正苦於以下問題:Java RequestBuilder.addParameter方法的具體用法?Java RequestBuilder.addParameter怎麽用?Java RequestBuilder.addParameter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.client.methods.RequestBuilder
的用法示例。
在下文中一共展示了RequestBuilder.addParameter方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildHttpUriRequest
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
protected HttpUriRequest buildHttpUriRequest(RequestBuilder builder) {
RequestBuilder requestBuilder = builder.setUri(this.address);
if (this.param != null && !this.param.isEmpty()) {
for (Map.Entry<String, String> entry : this.param.entrySet()) {
requestBuilder.addParameter(new BasicNameValuePair(entry.getKey(), entry.getValue()));
}
}
if (this.header != null) {
for (String name : this.header) {
requestBuilder.addHeader(name, this.header.getHeader(name));
}
}
RequestConfig requestConfig = RequestConfig.custom()
.setSocketTimeout(30000)
.setConnectTimeout(this.connectTimeout)
.setConnectionRequestTimeout(this.readTimeout)
.build();
requestBuilder.setConfig(requestConfig);
return requestBuilder.build();
}
示例2: buildGetRequest
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
protected HttpUriRequest buildGetRequest(String apiCall, List<NameValuePair> nameValuePairs) {
RequestBuilder requestBuilder = RequestBuilder.get(String.format(URL_CONCAT, getBaseUrl(), apiCall));
requestBuilder = addHeaders(requestBuilder);
for (NameValuePair nameValuePair : nameValuePairs) {
requestBuilder.addParameter(nameValuePair);
}
return requestBuilder.build();
}
示例3: buildTokenAuthURI
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
static URI buildTokenAuthURI(final String clientId, final String authRedirect, final String... authScopes) {
final RequestBuilder rb = RequestBuilder.get(BASE_URL_TOKEN_AUTH);
rb.addParameter("response_type", "token");
rb.addParameter("client_id", clientId);
rb.addParameter("redirect_uri", authRedirect);
rb.addParameter("scope", String.join(" ", authScopes));
return rb.build().getURI();
}
示例4: addGetParams
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
private HttpUriRequest addGetParams(RequestBuilder requestBuilder, String login, String email, String name, String subject, String content) {
requestBuilder.addParameter("login", login);
requestBuilder.addParameter("email", email);
requestBuilder.addParameter("name", name);
requestBuilder.addParameter("subject", subject);
requestBuilder.addParameter("content", content);
return requestBuilder.build();
}
示例5: build
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
public HttpUriRequest build() {
validate();
final RequestBuilder builder = RequestBuilder.create(method.toString()).setUri(buildUri());
if (!methodParameters.isEmpty()) {
for (final Entry<String, String> entry : methodParameters.entrySet()) {
builder.addParameter(entry.getKey(), entry.getValue());
}
}
if (jsonPayload.isPresent()) {
builder.addHeader(new BasicHeader(CONTENT_TYPE, JSON_CONTENT_TYPE))
.setEntity(new StringEntity(jsonPayload.get(), ContentType.create(JSON_CONTENT_TYPE, Consts.UTF_8)));
}
return builder.build();
}
示例6: executeServerQueryRaw
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
private <T> ServerQueryResponse<T> executeServerQueryRaw(
@Nullable final QueryOptions<T> options,
@Nullable final String wait,
final ValueExtractor<T> valueExtractor,
RequestBuilder requestBuilder
) throws IOException, NomadException {
String region = apiClient.getConfig().getRegion();
String namespace = apiClient.getConfig().getNamespace();
String authToken = apiClient.getConfig().getAuthToken();
if (options != null) {
if (options.getRegion() != null)
region = options.getRegion();
if (options.getNamespace() != null)
namespace = options.getNamespace();
if (options.getAuthToken() != null)
authToken = options.getAuthToken();
if (options.getIndex() != null)
requestBuilder.addParameter("index", options.getIndex().toString());
if (wait != null)
requestBuilder.addParameter("wait", wait);
if (options.isAllowStale())
requestBuilder.addParameter("stale", null);
}
if (region != null)
requestBuilder.addParameter("region", region);
if (namespace != null)
requestBuilder.addParameter("namespace", namespace);
if (authToken != null)
requestBuilder.addHeader("X-Nomad-Token", authToken);
return apiClient.execute(requestBuilder, new ServerQueryResponseAdapter<>(valueExtractor));
}
示例7: privateRequest
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
private ApiResponse privateRequest(String httpMethod, String endpoint, String body, HashMap<String, String> query, int requestcount) {
if (!ApiSettings.isValid())
throw new IllegalStateException("ApiSettings have an invalid state");
String endpointFinal = ApiSettings.getApiEndpoint() + endpoint;
try {
StringEntity entity = new StringEntity(body, ContentType.APPLICATION_JSON);
RequestBuilder requestBuilder = RequestBuilder.create(httpMethod);
requestBuilder.addHeader("Voat-ApiKey", ApiSettings.getPublicKey());
requestBuilder.setUri(endpointFinal);
if (!httpMethod.equals("GET"))
requestBuilder.setEntity(entity);
if (query != null)
for (String key : query.keySet()) {
requestBuilder.addParameter(key, query.get(key));
}
HttpUriRequest build = requestBuilder.build();
Authenticator.getInstance().authenticateRequest(build);
String s = HttpHelper.sendRequest(build);
HashMap<String, Object> json = JsonHelper.getInstance().fromJson(s);
return new ApiResponse(json);
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例8: addRequestParams
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
protected void addRequestParams(RequestBuilder builder) {
final Set<String> keySet = requestParams.keySet();
for (String key : keySet) {
builder.addParameter(key, requestParams.get(key));
}
}
示例9: toHttpUriRequest
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
HttpUriRequest toHttpUriRequest(Request request, Request.Options options) throws
UnsupportedEncodingException, MalformedURLException, URISyntaxException {
RequestBuilder requestBuilder = RequestBuilder.create(request.method());
//per request timeouts
RequestConfig requestConfig = RequestConfig
.custom()
.setConnectTimeout(options.connectTimeoutMillis())
.setSocketTimeout(options.readTimeoutMillis())
.build();
requestBuilder.setConfig(requestConfig);
URI uri = new URIBuilder(request.url()).build();
requestBuilder.setUri(uri.getScheme() + "://" + uri.getAuthority() + uri.getRawPath());
//request query params
List<NameValuePair> queryParams = URLEncodedUtils.parse(uri, requestBuilder.getCharset().name
());
for (NameValuePair queryParam : queryParams) {
requestBuilder.addParameter(queryParam);
}
//request headers
boolean hasAcceptHeader = false;
for (Map.Entry<String, Collection<String>> headerEntry : request.headers().entrySet()) {
String headerName = headerEntry.getKey();
if (headerName.equalsIgnoreCase(ACCEPT_HEADER_NAME)) {
hasAcceptHeader = true;
}
if (headerName.equalsIgnoreCase(Util.CONTENT_LENGTH)) {
// The 'Content-Length' header is always set by the Apache client and it
// doesn't like us to set it as well.
continue;
}
for (String headerValue : headerEntry.getValue()) {
requestBuilder.addHeader(headerName, headerValue);
}
}
//some servers choke on the default accept string, so we'll set it to anything
if (!hasAcceptHeader) {
requestBuilder.addHeader(ACCEPT_HEADER_NAME, "*/*");
}
//request body
if (request.body() != null) {
HttpEntity entity = null;
if (request.charset() != null) {
ContentType contentType = getContentType(request);
String content = new String(request.body(), request.charset());
entity = new StringEntity(content, contentType);
} else {
entity = new ByteArrayEntity(request.body());
}
requestBuilder.setEntity(entity);
}
return requestBuilder.build();
}
示例10: leader
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
/**
* Queries the address of the Raft leader in the given or active region.
*
* @param region the region to forward the request to
* @throws IOException if there is an HTTP or lower-level problem
* @throws NomadException if the response signals an error or cannot be deserialized
* @see <a href="https://www.nomadproject.io/docs/http/status.html">{@code GET /v1/status/peers}</a>
*/
public NomadResponse<String> leader(@Nullable String region) throws IOException, NomadException {
final RequestBuilder request = get("/v1/status/leader");
if (region != null)
request.addParameter("region", region);
return executePlain(request, NomadJson.parserFor(String.class));
}
示例11: peers
import org.apache.http.client.methods.RequestBuilder; //導入方法依賴的package包/類
/**
* List the addresses of the Raft peers in the given or active region.
*
* @param region the region to forward the request to
* @throws IOException if there is an HTTP or lower-level problem
* @throws NomadException if the response signals an error or cannot be deserialized
* @see <a href="https://www.nomadproject.io/docs/http/status.html">{@code GET /v1/status/peers}</a>
*/
public NomadResponse<List<String>> peers(@Nullable String region) throws IOException, NomadException {
RequestBuilder request = get("/v1/status/peers");
if (region != null)
request.addParameter("region", region);
return executePlain(request, NomadJson.parserForListOf(String.class));
}