本文整理汇总了Java中org.apache.commons.httpclient.methods.GetMethod.addRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java GetMethod.addRequestHeader方法的具体用法?Java GetMethod.addRequestHeader怎么用?Java GetMethod.addRequestHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.GetMethod
的用法示例。
在下文中一共展示了GetMethod.addRequestHeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResource
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
* Gets remote resource.
*
* @return the remove resource
*
* @throws ResourceException thrown if the resource could not be fetched
*/
protected GetMethod getResource() throws ResourceException {
GetMethod getMethod = new GetMethod(resourceUrl);
getMethod.addRequestHeader("Connection", "close");
try {
httpClient.executeMethod(getMethod);
if (getMethod.getStatusCode() != HttpStatus.SC_OK) {
throw new ResourceException("Unable to retrieve resource URL " + resourceUrl
+ ", received HTTP status code " + getMethod.getStatusCode());
}
return getMethod;
} catch (IOException e) {
throw new ResourceException("Unable to contact resource URL: " + resourceUrl, e);
}
}
示例2: buildGetMethod
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
/**
* Builds the HTTP GET method used to fetch the metadata. The returned method advertises support for GZIP and
* deflate compression, enables conditional GETs if the cached metadata came with either an ETag or Last-Modified
* information, and sets up basic authentication if such is configured.
*
* @return the constructed GET method
*/
protected GetMethod buildGetMethod() {
GetMethod getMethod = new GetMethod(getMetadataURI());
getMethod.addRequestHeader("Connection", "close");
getMethod.setRequestHeader("Accept-Encoding", "gzip,deflate");
if (cachedMetadataETag != null) {
getMethod.setRequestHeader("If-None-Match", cachedMetadataETag);
}
if (cachedMetadataLastModified != null) {
getMethod.setRequestHeader("If-Modified-Since", cachedMetadataLastModified);
}
if (httpClient.getState().getCredentials(authScope) != null) {
log.debug("Using BASIC authentication when retrieving metadata from '{}", metadataURI);
getMethod.setDoAuthentication(true);
}
return getMethod;
}
示例3: get
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public HttpResponse get(final RequestContext rq, final String scope, final int version, final String entityCollectionName, final Object entityId,
final String relationCollectionName, final Object relationshipEntityId, Map<String, String> params, Map<String, String> headers) throws IOException
{
if (headers == null)
{
headers = Collections.emptyMap();
}
RestApiEndpoint endpoint = new RestApiEndpoint(rq.getNetworkId(), scope, version, entityCollectionName, entityId, relationCollectionName,
relationshipEntityId, params);
String url = endpoint.getUrl();
GetMethod req = new GetMethod(url);
for (Entry<String, String> header : headers.entrySet())
{
req.addRequestHeader(header.getKey(), header.getValue());
}
return submitRequest(req, rq);
}
示例4: testCustomAuthorizationHeader
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public void testCustomAuthorizationHeader() throws Exception {
UsernamePasswordCredentials creds =
new UsernamePasswordCredentials("testuser", "testpass");
HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
handlerchain.appendHandler(new AuthRequestHandler(creds));
handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));
this.server.setRequestHandler(handlerchain);
GetMethod httpget = new GetMethod("/test/");
String authResponse = "Basic " + EncodingUtil.getAsciiString(
Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
httpget.addRequestHeader(new Header("Authorization", authResponse));
try {
this.client.executeMethod(httpget);
} finally {
httpget.releaseConnection();
}
assertNotNull(httpget.getStatusLine());
assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
}
示例5: getWithRealHeader
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String getWithRealHeader(String url) throws IOException {
// clearCookies();
GetMethod g = new GetMethod(url);
////////////////////////
g.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;");
g.addRequestHeader("Accept-Language", "zh-cn");
g.addRequestHeader("User-Agent", "Mozilla/5.0 (Windows; U; Windows NT 5.1; zh-CN; rv:1.9.0.3) Gecko/2008092417 Firefox/3.0.3");
g.addRequestHeader("Keep-Alive", "300");
g.addRequestHeader("Connection", "Keep-Alive");
g.addRequestHeader("Cache-Control", "no-cache");
///////////////////////
hc.executeMethod(g);
return g.getResponseBodyAsString();
}
示例6: get
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String get(String url, String cookies) throws
IOException {
// clearCookies();
GetMethod g = new GetMethod(url);
g.setFollowRedirects(false);
if (StringUtils.isNotEmpty(cookies)) {
g.addRequestHeader("cookie", cookies);
}
hc.executeMethod(g);
return g.getResponseBodyAsString();
}
示例7: getHeader
import org.apache.commons.httpclient.methods.GetMethod; //导入方法依赖的package包/类
public String getHeader(String url, String cookies, String headername) throws IOException {
// clearCookies();
GetMethod g = new GetMethod(url);
g.setFollowRedirects(false);
if (StringUtils.isNotEmpty(cookies)) {
g.addRequestHeader("cookie", cookies);
}
hc.executeMethod(g);
return g.getResponseHeader(headername) == null ? null : g.getResponseHeader(headername).getValue();
}