本文整理匯總了Java中org.apache.http.HttpEntityEnclosingRequest.addHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpEntityEnclosingRequest.addHeader方法的具體用法?Java HttpEntityEnclosingRequest.addHeader怎麽用?Java HttpEntityEnclosingRequest.addHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.http.HttpEntityEnclosingRequest
的用法示例。
在下文中一共展示了HttpEntityEnclosingRequest.addHeader方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testSimpleSigner
import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testSimpleSigner() throws Exception {
HttpEntityEnclosingRequest request =
new BasicHttpEntityEnclosingRequest("GET", "/query?a=b");
request.setEntity(new StringEntity("I'm an entity"));
request.addHeader("foo", "bar");
request.addHeader("content-length", "0");
HttpCoreContext context = new HttpCoreContext();
context.setTargetHost(HttpHost.create("localhost"));
createInterceptor().process(request, context);
assertEquals("bar", request.getFirstHeader("foo").getValue());
assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
assertNull(request.getFirstHeader("content-length"));
}
開發者ID:awslabs,項目名稱:aws-request-signing-apache-interceptor,代碼行數:18,代碼來源:AWSRequestSigningApacheInterceptorTest.java
示例2: testEncodedUriSigner
import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
@Test
public void testEncodedUriSigner() throws Exception {
HttpEntityEnclosingRequest request =
new BasicHttpEntityEnclosingRequest("GET", "/foo-2017-02-25%2Cfoo-2017-02-26/_search?a=b");
request.setEntity(new StringEntity("I'm an entity"));
request.addHeader("foo", "bar");
request.addHeader("content-length", "0");
HttpCoreContext context = new HttpCoreContext();
context.setTargetHost(HttpHost.create("localhost"));
createInterceptor().process(request, context);
assertEquals("bar", request.getFirstHeader("foo").getValue());
assertEquals("wuzzle", request.getFirstHeader("Signature").getValue());
assertNull(request.getFirstHeader("content-length"));
assertEquals("/foo-2017-02-25%2Cfoo-2017-02-26/_search", request.getFirstHeader("resourcePath").getValue());
}
開發者ID:awslabs,項目名稱:aws-request-signing-apache-interceptor,代碼行數:19,代碼來源:AWSRequestSigningApacheInterceptorTest.java
示例3: generate
import org.apache.http.HttpEntityEnclosingRequest; //導入方法依賴的package包/類
public synchronized byte[] generate(QUser user, String uri, HashMap<String, String> params) {
final HttpEntityEnclosingRequest r = new BasicHttpEntityEnclosingRequest("POST", uri);
r.addHeader("Cookie", "username=" + user.getName() + "; password=" + user.getPassword());
final StringBuilder sb = new StringBuilder();
params.keySet().stream().forEach((st) -> {
sb.append("&").append(st).append("=").append(params.get(st));
});
final InputStream is = new ByteArrayInputStream(sb.substring(1).getBytes());
final BasicHttpEntity b = new BasicHttpEntity();
b.setContent(is);
r.setEntity(b);
sb.setLength(0);
return generate(r).getData();
}