當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。