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