本文整理汇总了Java中org.apache.commons.httpclient.HttpMethod.setURI方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.setURI方法的具体用法?Java HttpMethod.setURI怎么用?Java HttpMethod.setURI使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.setURI方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeURI
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Execute a transaction method given a complete URI.
* @param method the transaction method
* @param headers HTTP header values to send
* @param uri a properly urlencoded URI
* @return the HTTP response code
* @throws IOException
*/
public int executeURI(HttpMethod method, Header[] headers, String uri)
throws IOException {
method.setURI(new URI(uri, true));
for (Map.Entry<String, String> e: extraHeaders.entrySet()) {
method.addRequestHeader(e.getKey(), e.getValue());
}
if (headers != null) {
for (Header header: headers) {
method.addRequestHeader(header);
}
}
long startTime = System.currentTimeMillis();
int code = httpClient.executeMethod(method);
long endTime = System.currentTimeMillis();
if (LOG.isDebugEnabled()) {
LOG.debug(method.getName() + " " + uri + " " + code + " " +
method.getStatusText() + " in " + (endTime - startTime) + " ms");
}
return code;
}
示例2: sendRemoteRequest
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Send Request to the repository
*/
protected HttpMethod sendRemoteRequest(Request req) throws AuthenticationException, IOException
{
if (logger.isDebugEnabled())
{
logger.debug("");
logger.debug("* Request: " + req.getMethod() + " " + req.getFullUri() + (req.getBody() == null ? "" : "\n" + new String(req.getBody(), "UTF-8")));
}
HttpMethod method = createMethod(req);
// execute method
executeMethod(method);
// Deal with redirect
if(isRedirect(method))
{
Header locationHeader = method.getResponseHeader("location");
if (locationHeader != null)
{
String redirectLocation = locationHeader.getValue();
method.setURI(new URI(redirectLocation, true));
httpClient.executeMethod(method);
}
}
return method;
}