本文整理汇总了Java中org.apache.http.HttpHost.toURI方法的典型用法代码示例。如果您正苦于以下问题:Java HttpHost.toURI方法的具体用法?Java HttpHost.toURI怎么用?Java HttpHost.toURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.HttpHost
的用法示例。
在下文中一共展示了HttpHost.toURI方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getModSlug0
import org.apache.http.HttpHost; //导入方法依赖的package包/类
@Nullable
private String getModSlug0(int id)
{
try
{
log.debug("Getting mod slug from server...");
URI uri = getURI(CURSEFORGE_URL, String.format(PROJECT_PATH, id), null);
HttpGet request = new HttpGet(uri.toURL().toString());
HttpContext context = new BasicHttpContext();
HttpResponse response = http.execute(request, context);
EntityUtils.consume(response.getEntity());
HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute(HttpCoreContext.HTTP_REQUEST);
HttpHost currentHost = (HttpHost) context.getAttribute(HttpCoreContext.HTTP_TARGET_HOST);
String currentUrl = (currentReq.getURI().isAbsolute()) ? currentReq.getURI().toString() : (currentHost.toURI() + currentReq.getURI());
Splitter splitter = Splitter.on('/').omitEmptyStrings();
List<String> pathParts = splitter.splitToList(currentUrl);
return pathParts.get(pathParts.size() - 1);
}
catch (Exception e)
{
log.error("Failed to perform request from CurseForge site.", e);
return null;
}
}
示例2: getHttpResponse
import org.apache.http.HttpHost; //导入方法依赖的package包/类
/**
* Send the specified GET request to the indicated host.
*
* @param host target HTTP host connection
* @param request request path (may include parameters)
* @return host response for the specified GET request
* @throws IOException The request triggered an I/O exception
*/
public static HttpResponse getHttpResponse(HttpHost host, String request) throws IOException {
HttpClient client = HttpClientBuilder.create().build();
URL sessionURL = new URL(host.toURI() + request);
BasicHttpEntityEnclosingRequest basicHttpEntityEnclosingRequest =
new BasicHttpEntityEnclosingRequest("GET", sessionURL.toExternalForm());
return client.execute(host, basicHttpEntityEnclosingRequest);
}