本文整理汇总了Java中org.apache.http.client.methods.HttpPost.getURI方法的典型用法代码示例。如果您正苦于以下问题:Java HttpPost.getURI方法的具体用法?Java HttpPost.getURI怎么用?Java HttpPost.getURI使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.methods.HttpPost
的用法示例。
在下文中一共展示了HttpPost.getURI方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: importResolvedIssues
import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
private String importResolvedIssues(final String projectKey, final String data) {
// Cannot use query because we use the fileupload
LOGGER.info("Importing issues into project {}", projectKey);
// Use httpclient 4
final CredentialsProvider provider = new BasicCredentialsProvider();
provider.setCredentials(AuthScope.ANY,
new UsernamePasswordCredentials(Server.ADMIN_LOGIN, Server.ADMIN_PASSWORD));
final AuthCache authCache = new BasicAuthCache();
authCache.put(new HttpHost("localhost", orchestrator.getServer().port()), new BasicScheme());
final HttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(provider).build();
final HttpClientContext context = HttpClientContext.create();
context.setCredentialsProvider(provider);
context.setAuthCache(authCache);
final HttpPost post = new HttpPost(orchestrator.getServer().getUrl() + "/"
+ IssueResolverWebService.CONTROLLER_PATH + "/" + ImportAction.ACTION);
post.setHeader("Accept", "application/json");
// Set data
final MultipartEntityBuilder builder = MultipartEntityBuilder.create();
builder.setMode(HttpMultipartMode.BROWSER_COMPATIBLE);
builder.addPart("projectKey", new StringBody(projectKey, ContentType.MULTIPART_FORM_DATA));
builder.addPart("data",
new ByteArrayBody(data.getBytes(), ContentType.MULTIPART_FORM_DATA, "resolved-issues.json"));
post.setEntity(builder.build());
try {
final HttpResponse response = client.execute(post, context);
final HttpEntity entity = response.getEntity();
if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
return EntityUtils.toString(entity);
} else {
throw new ConnectionException("HTTP error: " + response.getStatusLine().getStatusCode() + ", msg: "
+ response.getStatusLine().getReasonPhrase() + ", query: " + post.toString());
}
} catch (IOException e) {
throw new ConnectionException("Query: " + post.getURI(), e);
} finally {
post.releaseConnection();
}
}