當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。