本文整理汇总了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());
}
}
}
示例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());
}
示例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();
}
}
}
示例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");
}
示例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;
}
示例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());
}
示例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());
}