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