当前位置: 首页>>代码示例>>Java>>正文


Java HttpMethodBase.addRequestHeader方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.HttpMethodBase.addRequestHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethodBase.addRequestHeader方法的具体用法?Java HttpMethodBase.addRequestHeader怎么用?Java HttpMethodBase.addRequestHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.HttpMethodBase的用法示例。


在下文中一共展示了HttpMethodBase.addRequestHeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setupHTTPRequestHeaderProperties

import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
 * This function sets the header properties in the HTTP method.
 * 
 * @param   httpRequest
 *          The HTTP request
 * @param   httpMethodClient
 *          The apache HTTP method
 */
protected void setupHTTPRequestHeaderProperties(HTTPRequest httpRequest,HttpMethodBase httpMethodClient)
{
    //setup header properties
    Properties headerProperties=httpRequest.getHeaderProperties();
    if(headerProperties!=null)
    {
        Iterator<Entry<Object,Object>> iterator=headerProperties.entrySet().iterator();
        Entry<Object,Object> entry=null;
        while(iterator.hasNext())
        {
            //get next entry
            entry=iterator.next();
            
            //set header values
            httpMethodClient.addRequestHeader((String)entry.getKey(),(String)entry.getValue());
        }
    }
}
 
开发者ID:sagiegurari,项目名称:fax4j,代码行数:27,代码来源:ApacheHTTPClient.java

示例2: setHeaders

import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
 * Add the headers to the method, and the auth token (which must be set
 * @param method method to update
 * @param requestHeaders the list of headers
 * @throws SwiftInternalStateException not yet authenticated
 */
private void setHeaders(HttpMethodBase method, Header[] requestHeaders)
    throws SwiftInternalStateException {
    for (Header header : requestHeaders) {
      method.addRequestHeader(header);
    }
  setAuthToken(method, getToken());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:14,代码来源:SwiftRestClient.java

示例3: executeMethod

import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
private static byte[] executeMethod(HttpMethodBase method, int timeout) throws Exception {
    InputStream in = null;
    try {
        method.addRequestHeader("Connection", "close");
        HttpClient client = new HttpClient();
        HttpConnectionManagerParams params = client.getHttpConnectionManager().getParams();
        //设置连接时候一些参数
        params.setConnectionTimeout(timeout);
        params.setSoTimeout(timeout);
        params.setStaleCheckingEnabled(false);
        ByteArrayOutputStream baos = new ByteArrayOutputStream(BUFFER_SIZE);

        int stat =  client.executeMethod(method);
        if (stat != HttpStatus.SC_OK)
            log.error("get失败!");

        //method.getResponseBody()
        in = method.getResponseBodyAsStream();
        byte[] buffer = new byte[BUFFER_SIZE];
        int len;
        while ((len = in.read(buffer)) > 0) {
            baos.write(buffer, 0, len);
        }
        return baos.toByteArray();
    }
    finally {
        if (in != null) {
            in.close();
        }
    }
}
 
开发者ID:ggj2010,项目名称:javabase,代码行数:32,代码来源:OldHttpClientApi.java

示例4: setHeader

import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
 * 
 * 设置请求头方法
 * 
 * @author zcj
 * @param hmb GetMethod or PostMethod
 * @time 2016-10-13 09:51:18
 * 
 */
static void setHeader(HttpMethodBase hmb) {
	hmb.addRequestHeader("Cache-Control", "no-cache");
	hmb.addRequestHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8");
	hmb.addRequestHeader("Accept-Encoding", "gzip, deflate, sdch");
	hmb.addRequestHeader("Accept-Language", "zh-CN,zh;q=0.8");
	hmb.addRequestHeader("Cache-Control", "max-age=0");
	hmb.addRequestHeader("Connection", "Keep-Alive");
	hmb.addRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	hmb.addRequestHeader("Host", "kyfw.12306.cn");
	hmb.addRequestHeader("Upgrade-Insecure-Requests", "1");
	hmb.addRequestHeader("Referer", "https://kyfw.12306.cn/otn/login/init");
	hmb.addRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
}
 
开发者ID:WilleamZhao,项目名称:sourcod,代码行数:23,代码来源:Tool12306Util.java

示例5: setHeader

import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
private HttpMethodBase setHeader(HttpMethodBase method) {
    Map<String, List<String>> value = getNameValuePairs(header, "header");
    if (value != null) {
        for (Map.Entry<String, List<String>> entry : value.entrySet()) {
            for (String v : entry.getValue()) {
                method.addRequestHeader(entry.getKey(), v);
            }
        }
    } else if (header != null) {
        throw new PaxmlRuntimeException("Header should be key-value pairs but got: " + header);
    }
    return method;
}
 
开发者ID:niuxuetao,项目名称:paxml,代码行数:14,代码来源:HttpTag.java

示例6: addPostHeaders

import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
private void addPostHeaders(HttpMethodBase method) {
    method.addRequestHeader("Accept", "application/json, text/plain, */*");
    method.addRequestHeader("Content-Type", "application/json");
    method.addRequestHeader("Authorization", "Basic " + conn.getBasicAuthHeader());
}
 
开发者ID:KylinOLAP,项目名称:Kylin,代码行数:6,代码来源:KylinClient.java

示例7: setAuthToken

import org.apache.commons.httpclient.HttpMethodBase; //导入方法依赖的package包/类
/**
 * Set the auth key header of the method to the token ID supplied
 *
 * @param method method
 * @param accessToken access token
 * @throws SwiftInternalStateException if the client is not yet authenticated
 */
private void setAuthToken(HttpMethodBase method, AccessToken accessToken)
    throws SwiftInternalStateException {
  checkNotNull(accessToken,"Not authenticated");
  method.addRequestHeader(HEADER_AUTH_KEY, accessToken.getId());
}
 
开发者ID:naver,项目名称:hadoop,代码行数:13,代码来源:SwiftRestClient.java


注:本文中的org.apache.commons.httpclient.HttpMethodBase.addRequestHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。