本文整理汇总了Java中org.apache.http.client.methods.HttpUriRequest.setHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpUriRequest.setHeader方法的具体用法?Java HttpUriRequest.setHeader怎么用?Java HttpUriRequest.setHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.client.methods.HttpUriRequest
的用法示例。
在下文中一共展示了HttpUriRequest.setHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: rawPost
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public void rawPost(String str, ArrayList<KVPair<String>> arrayList, HTTPPart hTTPPart,
HttpResponseCallback httpResponseCallback) throws Throwable {
long currentTimeMillis = System.currentTimeMillis();
Ln.i("raw post: " + str, new Object[0]);
HttpUriRequest httpPost = new HttpPost(str);
if (arrayList != null) {
Iterator it = arrayList.iterator();
while (it.hasNext()) {
KVPair kVPair = (KVPair) it.next();
httpPost.setHeader(kVPair.name, (String) kVPair.value);
}
}
httpPost.setEntity(hTTPPart.getInputStreamEntity());
HttpClient sSLHttpClient = str.startsWith("https://") ? getSSLHttpClient() : new
DefaultHttpClient();
HttpResponse execute = sSLHttpClient.execute(httpPost);
if (httpResponseCallback != null) {
httpResponseCallback.onResponse(execute);
}
sSLHttpClient.getConnectionManager().shutdown();
Ln.i("use time: " + (System.currentTimeMillis() - currentTimeMillis), new Object[0]);
}
示例2: execute
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
protected HttpResponse execute(HttpUriRequest request, boolean consume, String token)
throws ClientProtocolException, IOException
{
if( token != null )
{
final Header tokenHeader = new BasicHeader("X-Authorization", token);
request.setHeader(tokenHeader);
}
request.setHeader("X-Autotest-Key", context.getFullName(""));
HttpResponse response = getClient().execute(request);
if( consume )
{
EntityUtils.consume(response.getEntity());
}
return response;
}
示例3: send
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
/**
* Makes a HTTP request to the given URL using the given request body,
* parameters and HTTP headers. The parameters are used as URL parameters,
* but if there's a parameter "resourceId", it's added directly to the end
* of the URL. If there's no request body, the value can be null.
*
* @param url URL where the request is sent
* @param params request parameters
* @param requestBody request body
* @param headers HTTP headers to be added to the request
* @return response as string
*/
@Override
public ClientResponse send(String url, String requestBody, Map<String, ?> params, Map<String, String> headers) {
// Build target URL
url = ClientUtil.buildTargetURL(url, params);
// Create HTTP client
CloseableHttpClient httpClient = HttpClients.createDefault();
// Build request
HttpUriRequest request = this.buildtHttpRequest(url, requestBody, headers);
LOGGER.info("Starting HTTP {} operation.", request.getMethod());
// Add headers
if (headers != null && !headers.isEmpty()) {
for (Map.Entry<String, String> entry : headers.entrySet()) {
LOGGER.debug("Add header : \"{}\" = \"{}\"", entry.getKey(), entry.getValue());
request.setHeader(entry.getKey(), entry.getValue());
}
}
try {
//Send the request; It will immediately return the response in HttpResponse object
CloseableHttpResponse response = httpClient.execute(request);
// Get Content-Type header
Header[] contentTypeHeader = response.getHeaders("Content-Type");
String contentType = null;
// Check for null and empty
if (contentTypeHeader != null && contentTypeHeader.length > 0) {
contentType = contentTypeHeader[0].getValue();
}
// Get Status Code
int statusCode = response.getStatusLine().getStatusCode();
// Get reason phrase
String reasonPhrase = response.getStatusLine().getReasonPhrase();
// Get response payload
String responseStr = ClientUtil.getResponseString(response.getEntity());
response.close();
httpClient.close();
LOGGER.debug("REST response content type: \"{}\".", contentType);
LOGGER.debug("REST response status code: \"{}\".", statusCode);
LOGGER.debug("REST response reason phrase: \"{}\".", reasonPhrase);
LOGGER.debug("REST response : \"{}\".", responseStr);
LOGGER.info("HTTP {} operation completed.", request.getMethod());
return new ClientResponse(responseStr, contentType, statusCode, reasonPhrase);
} catch (IOException e) {
LOGGER.error(e.getMessage(), e);
LOGGER.warn("HTTP {} operation failed. An empty string is returned.", request.getMethod());
return null;
}
}
示例4: updateRequestHeaders
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public void updateRequestHeaders(HttpUriRequest uriRequest) {
if (mFile.exists() && mFile.canWrite())
current = mFile.length();
if (current > 0) {
append = true;
uriRequest.setHeader("Range", "bytes=" + current + "-");
}
}
示例5: generateHttpRequest
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
protected HttpUriRequest generateHttpRequest(Site site,Request request,HttpHost proxy){
RequestBuilder requestBuilder = selectRequestMethod(request).setUri(request.getUrl());
if (site.getHeaders() != null) {
for (Map.Entry<String, String> headerEntry : site.getHeaders().entrySet()) {
requestBuilder.setHeader(headerEntry.getKey(), headerEntry.getValue());
}
}
RequestConfig.Builder requestConfigBuilder = RequestConfig.custom();
if (site != null) {
requestConfigBuilder.setConnectionRequestTimeout(site.getTimeout())
.setSocketTimeout(site.getTimeout())
.setConnectTimeout(site.getTimeout())
.setCookieSpec(CookieSpecs.STANDARD);
}
if (proxy != null) {
requestConfigBuilder.setProxy(proxy);
}
requestBuilder.setConfig(requestConfigBuilder.build());
HttpUriRequest httpUriRequest = requestBuilder.build();
if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
for (Map.Entry<String, String> header : request.getHeaders().entrySet()) {
httpUriRequest.setHeader(header.getKey(), header.getValue());
}
}
return httpUriRequest;
}
示例6: createGetCaptchaImageRequest
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
@Override
public HttpUriRequest createGetCaptchaImageRequest(CEIDGCaptchaSessionResource ceidgCaptchaSessionResource) {
URI uri = buildURI(ceidgCaptchaSessionResource);
String cookieString = getCookieString(ceidgCaptchaSessionResource);
HttpUriRequest httpUriRequest = new HttpGet(uri);
httpUriRequest.setHeader("Cookie", cookieString);
return httpUriRequest;
}
示例7: if
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
private HttpResponse b0449щ0449щщ0449(HttpUriRequest httpUriRequest, Map map, int i) throws Exception {
URI uri = httpUriRequest.getURI();
String trim = uri.getHost() != null ? uri.getHost().trim() : "";
if (trim.length() > 0) {
httpUriRequest.setHeader("Host", trim);
}
if (map != null) {
for (Object next : map.entrySet()) {
if (((b04170417041704170417З + b0417ЗЗЗЗ0417) * b04170417041704170417З) % bЗ0417ЗЗЗ0417 != bЗЗЗЗЗ0417) {
b04170417041704170417З = 81;
bЗЗЗЗЗ0417 = 31;
}
Entry entry = (Entry) next;
httpUriRequest.setHeader((String) entry.getKey(), (String) entry.getValue());
}
}
Header[] allHeaders = httpUriRequest.getAllHeaders();
Log.d(b043D043Dнн043Dн, "request URI [" + httpUriRequest.getURI() + "]");
for (Object obj : allHeaders) {
Log.d(b043D043Dнн043Dн, "request header [" + obj.toString() + "]");
}
HttpConnectionParams.setSoTimeout(this.bнн043Dн043Dн.getParams(), i);
HttpResponse execute = this.bнн043Dн043Dн.execute(httpUriRequest);
if (execute != null) {
return execute;
}
throw new RuntimeException("Null response returned.");
}
示例8: put
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
/**
* レスポンスボディを受ける PUTメソッド.
* @param url リクエスト対象URL
* @param data 書き込むデータ
* @param headers リクエストヘッダのハッシュマップ
* @return DcResponse型
* @throws PersoniumException DAO例外
*/
public final PersoniumResponse put(final String url,
final String data,
final HashMap<String, String> headers) throws PersoniumException {
String contentType = headers.get(HttpHeaders.CONTENT_TYPE);
HttpUriRequest req = makePutRequest(url, data, contentType);
for (Map.Entry<String, String> entry : headers.entrySet()) {
req.setHeader(entry.getKey(), entry.getValue());
}
req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());
debugHttpRequest(req, data);
PersoniumResponse res = request(req);
return res;
}
示例9: setHeaders
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
private void setHeaders(HttpUriRequest request, Map<String, String> headers) {
if (headers != null && !headers.isEmpty()) {
for (Map.Entry<String, String> header : headers.entrySet()) {
request.setHeader(header.getKey(), header.getValue());
}
}
}
示例10: post
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
/**
* リクエストボディを受け取る POSTメソッド.
* @param url リクエスト対象URL
* @param data 書き込むデータ
* @param headers リクエストヘッダのハッシュマップ
* @return DcResponse型
* @throws PersoniumException DAO例外
*/
public final PersoniumResponse post(final String url, final String data, final HashMap<String, String> headers)
throws PersoniumException {
String contentType = headers.get(HttpHeaders.CONTENT_TYPE);
HttpUriRequest req = makePostRequest(url, data, contentType);
for (Map.Entry<String, String> entry : headers.entrySet()) {
req.setHeader(entry.getKey(), entry.getValue());
}
req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());
debugHttpRequest(req, data);
PersoniumResponse res = request(req);
return res;
}
示例11: get
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
/**
* レスポンスボディを受け取るGETメソッド.
* @param url リクエスト対象URL
* @param headers リクエストヘッダのハッシュマップ
* @return DcResponse型
* @throws PersoniumException DAO例外
*/
public final PersoniumResponse get(final String url, final HashMap<String, String> headers)
throws PersoniumException {
HttpUriRequest req = new HttpGet(url);
for (Map.Entry<String, String> entry : headers.entrySet()) {
req.setHeader(entry.getKey(), entry.getValue());
}
req.addHeader("X-Personium-Version", PersoniumCoreTestConfig.getCoreVersion());
debugHttpRequest(req, "");
PersoniumResponse res = this.request(req);
return res;
}
示例12: updateRequestHeaders
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public void updateRequestHeaders(HttpUriRequest uriRequest) {
if (this.mFile.exists() && this.mFile.canWrite()) {
this.current = this.mFile.length();
}
if (this.current > 0) {
this.append = true;
uriRequest.setHeader("Range", "bytes=" + this.current + SocializeConstants.OP_DIVIDER_MINUS);
}
}
示例13: addHeaders
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
private static void addHeaders(HttpUriRequest httpRequest, Map<String, String> headers) {
for (String key : headers.keySet()) {
httpRequest.setHeader(key, headers.get(key));
}
}
示例14: reverseProxy
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
@RequestMapping("/**")
public void reverseProxy(HttpServletRequest request, HttpServletResponse response) throws IOException
{
if (googleToken == null || jweToken == null || jweToken.getJweToken() == null
|| jweToken.getEncodedJweToken() == null) {
logger.info("Redirecting to Google for authentication.");
initialRedirect = request.getRequestURI().toString();
response.sendRedirect(googleTokenRetriever.getAuthorizeUrl());
return;
}
InputStreamEntity inputStreamEntity = getInputStreamEntity(request);
HttpUriRequest proxiedRequest = buildHttpRequest(request.getMethod(),
k8sClusterEndpoint + request.getRequestURI(),
inputStreamEntity,
request);
Enumeration<String> headerNames = request.getHeaderNames();
while (headerNames.hasMoreElements()) {
String headerName = headerNames.nextElement();
if (!HttpHeaders.CONTENT_LENGTH.equalsIgnoreCase(headerName)
&& !HttpHeaders.TRANSFER_ENCODING.equalsIgnoreCase(headerName)) {
proxiedRequest.setHeader(headerName, request.getHeader(headerName));
}
}
ReadLock readLock = lock.readLock();
try {
readLock.lock();
proxiedRequest.setHeader(JWE_TOKEN, jweToken.getJweToken());
proxiedRequest.setHeader(HttpHeaders.AUTHORIZATION, BEARER_PREFIX + googleToken.getIdToken());
proxiedRequest.setHeader(HttpHeaders.COOKIE, jweToken.getEncodedJweToken());
} finally {
readLock.unlock();
}
try (CloseableHttpResponse proxiedResponse = httpClient.execute(proxiedRequest)) {
response.setStatus(proxiedResponse.getStatusLine().getStatusCode());
Stream.of(proxiedResponse.getAllHeaders())
.forEach(header -> response.setHeader(header.getName(), header.getValue()));
if (proxiedResponse.getEntity() != null) {
IOUtils.copy(proxiedResponse.getEntity().getContent(), response.getOutputStream());
}
}
}
示例15: upload
import org.apache.http.client.methods.HttpUriRequest; //导入方法依赖的package包/类
public static Statistic upload(Context context, String str, Bundle bundle) throws
MalformedURLException, IOException, NetworkUnavailableException, HttpStatusException {
int size;
int i;
byte[] byteArray;
if (context != null) {
ConnectivityManager connectivityManager = (ConnectivityManager) context
.getSystemService("connectivity");
if (connectivityManager != null) {
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo == null || !activeNetworkInfo.isAvailable()) {
throw new NetworkUnavailableException(NetworkUnavailableException.ERROR_INFO);
}
}
}
Bundle bundle2 = new Bundle(bundle);
String str2 = "";
str2 = bundle2.getString("appid_for_getting_config");
bundle2.remove("appid_for_getting_config");
HttpClient httpClient = HttpUtils.getHttpClient(context, str2, str);
HttpUriRequest httpPost = new HttpPost(str);
Bundle bundle3 = new Bundle();
for (String str22 : bundle2.keySet()) {
Object obj = bundle2.get(str22);
if (obj instanceof byte[]) {
bundle3.putByteArray(str22, (byte[]) obj);
}
}
httpPost.setHeader("Content-Type", "multipart/form-data; " +
"boundary=3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f");
httpPost.setHeader("Connection", "Keep-Alive");
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
byteArrayOutputStream.write(getBytesUTF8("--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
byteArrayOutputStream.write(getBytesUTF8(encodePostBody(bundle2,
"3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f")));
if (!bundle3.isEmpty()) {
size = bundle3.size();
byteArrayOutputStream.write(getBytesUTF8
("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
i = -1;
for (String str222 : bundle3.keySet()) {
i++;
byteArrayOutputStream.write(getBytesUTF8("Content-Disposition: form-data; " +
"name=\"" + str222 + "\"; filename=\"" + "value.file" + a.e + "\r\n"));
byteArrayOutputStream.write(getBytesUTF8("Content-Type: " +
"application/octet-stream\r\n\r\n"));
byteArray = bundle3.getByteArray(str222);
if (byteArray != null) {
byteArrayOutputStream.write(byteArray);
}
if (i < size - 1) {
byteArrayOutputStream.write(getBytesUTF8
("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f\r\n"));
}
}
}
byteArrayOutputStream.write(getBytesUTF8
("\r\n--3i2ndDfv2rTHiSisAbouNdArYfORhtTPEefj3q2f--\r\n"));
byteArray = byteArrayOutputStream.toByteArray();
i = byteArray.length + 0;
byteArrayOutputStream.close();
httpPost.setEntity(new ByteArrayEntity(byteArray));
HttpResponse execute = httpClient.execute(httpPost);
size = execute.getStatusLine().getStatusCode();
if (size == 200) {
return new Statistic(a(execute), i);
}
throw new HttpStatusException(HttpStatusException.ERROR_INFO + size);
}