本文整理匯總了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();
}
}