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


Java HttpPost.getURI方法代码示例

本文整理汇总了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();
	}
}
 
开发者ID:willemsrb,项目名称:sonar-issueresolver-plugin,代码行数:46,代码来源:PluginIT.java


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