本文整理汇总了Java中org.apache.http.client.entity.EntityBuilder.setContentEncoding方法的典型用法代码示例。如果您正苦于以下问题:Java EntityBuilder.setContentEncoding方法的具体用法?Java EntityBuilder.setContentEncoding怎么用?Java EntityBuilder.setContentEncoding使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.entity.EntityBuilder
的用法示例。
在下文中一共展示了EntityBuilder.setContentEncoding方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendFilePostRequest
import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
* Executes FILE (binary) HTTP POST request based on configuration
*
* @param config
* DPU configuration
* @param client
* HTTP client used to execute request
* @return HTTP response
* @throws Exception
* if request execution fails
*/
public CloseableHttpResponse sendFilePostRequest(HttpRequestConfig_V1 config, File file, CloseableHttpClient client) throws Exception {
CloseableHttpResponse response = null;
try {
URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
uriBuilder.setPath(uriBuilder.getPath());
HttpPost request = new HttpPost(uriBuilder.build().normalize());
// if (rdfConfig.isUseAuthentication()) {
// addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
// }
EntityBuilder builder = EntityBuilder.create();
builder.setContentEncoding(config.getCharset());
//ContentType contentType = ContentType.DEFAULT_BINARY;
ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
builder.setFile(file);
builder.setContentType(contentType);
HttpEntity entity = builder.build();
request.setEntity(entity);
request.addHeader("Content-Type", contentType.toString());
LOG.info("Request: {}", request.toString());
response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
//response = client.execute(request);
checkHttpResponseStatus(response);
} catch (URISyntaxException | IllegalStateException | IOException ex) {
String errorMsg = String.format("Failed to execute HTTP file POST request to URL %s", config.getRequestURL());
LOG.error(errorMsg, ex);
throw new Exception(errorMsg, ex);
}
return response;
}
示例2: sendFilePutRequest
import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
* Executes FILE (binary) HTTP PUT request based on configuration
*
* @param config
* DPU configuration
* @param client
* HTTP client used to execute request
* @return HTTP response
* @throws Exception
* if request execution fails
*/
public CloseableHttpResponse sendFilePutRequest(HttpRequestConfig_V1 config, File file, CloseableHttpClient client) throws Exception {
CloseableHttpResponse response = null;
try {
URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
uriBuilder.setPath(uriBuilder.getPath());
HttpPut request = new HttpPut(uriBuilder.build().normalize());
// if (rdfConfig.isUseAuthentication()) {
// addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
// }
EntityBuilder builder = EntityBuilder.create();
builder.setContentEncoding(config.getCharset());
//ContentType contentType = ContentType.DEFAULT_BINARY;
ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
builder.setFile(file);
builder.setContentType(contentType);
HttpEntity entity = builder.build();
request.setEntity(entity);
request.addHeader("Content-Type", contentType.toString());
LOG.info("Request: {}", request.toString());
response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
//response = client.execute(request);
checkHttpResponseStatus(response);
} catch (URISyntaxException | IllegalStateException | IOException ex) {
String errorMsg = String.format("Failed to execute HTTP file PUT request to URL %s", config.getRequestURL());
LOG.error(errorMsg, ex);
throw new Exception(errorMsg, ex);
}
return response;
}
示例3: sendRawDataPostRequest
import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
* Executes RAW data (text data) HTTP POST request based on configuration
*
* @param config
* DPU configuration
* @param client
* HTTP client used to execute request
* @return HTTP response
* @throws Exception
* if request execution fails
*/
public CloseableHttpResponse sendRawDataPostRequest(HttpRequestConfig_V1 config, CloseableHttpClient client) throws Exception {
CloseableHttpResponse response = null;
try {
URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
uriBuilder.setPath(uriBuilder.getPath());
HttpPost request = new HttpPost(uriBuilder.build().normalize());
// if (rdfConfig.isUseAuthentication()) {
// addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
// }
EntityBuilder builder = EntityBuilder.create();
builder.setContentEncoding(config.getCharset());
ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
builder.setText(config.getRawRequestBody());
builder.setContentType(contentType);
HttpEntity entity = builder.build();
request.setEntity(entity);
request.addHeader("Content-Type", contentType.toString());
response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
// response = client.execute(request);
checkHttpResponseStatus(response);
} catch (URISyntaxException | IllegalStateException | IOException ex) {
String errorMsg = String.format("Failed to execute HTTP raw POST request to URL %s", config.getRequestURL());
LOG.error(errorMsg);
throw new Exception(errorMsg, ex);
}
return response;
}
示例4: sendRawDataPutRequest
import org.apache.http.client.entity.EntityBuilder; //导入方法依赖的package包/类
/**
* Executes RAW data (text data) HTTP PUT request based on configuration
*
* @param config
* DPU configuration
* @param client
* HTTP client used to execute request
* @return HTTP response
* @throws Exception
* if request execution fails
*/
public CloseableHttpResponse sendRawDataPutRequest(HttpRequestConfig_V1 config, CloseableHttpClient client) throws Exception {
CloseableHttpResponse response = null;
try {
URIBuilder uriBuilder = new URIBuilder(config.getRequestURL());
uriBuilder.setPath(uriBuilder.getPath());
HttpPut request = new HttpPut(uriBuilder.build().normalize());
// if (rdfConfig.isUseAuthentication()) {
// addBasiAuthenticationForHttpRequest(request, rdfConfig.getUserName(), rdfConfig.getPassword());
// }
EntityBuilder builder = EntityBuilder.create();
builder.setContentEncoding(config.getCharset());
ContentType contentType = ContentType.create(config.getContentType().getDescription()).withCharset(config.getCharset());
builder.setText(config.getRawRequestBody());
builder.setContentType(contentType);
HttpEntity entity = builder.build();
request.setEntity(entity);
request.addHeader("Content-Type", contentType.toString());
response = this.httpWrapper.getClient().execute(this.httpWrapper.getHost(), request, this.httpWrapper.getContext());
// response = client.execute(request);
checkHttpResponseStatus(response);
} catch (URISyntaxException | IllegalStateException | IOException ex) {
String errorMsg = String.format("Failed to execute HTTP raw PUT request to URL %s", config.getRequestURL());
LOG.error(errorMsg);
throw new Exception(errorMsg, ex);
}
return response;
}