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


Java HttpEntityEnclosingRequestBase.addHeader方法代码示例

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


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

示例1: executeCallback

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
private void executeCallback(HttpEntityEnclosingRequestBase request, String json, FutureCallback<HttpResponse> httpCallback) {
	if (json != null && json.length() > 0) {
		request.addHeader("Content-Type", "application/json");
		if (!this.httpCompress) {
			request.setEntity(generateStringEntity(json));
		} else {
			request.addHeader("Accept-Encoding", "gzip, deflate");
			request.setEntity(generateGZIPCompressEntity(json));
		}
	}

	FutureCallback<HttpResponse> responseCallback = null;
	if (httpCallback != null) {
		unCompletedTaskNum.incrementAndGet();
		responseCallback = this.httpResponseCallbackFactory.wrapUpBaseHttpFutureCallback(httpCallback);
	}

	httpclient.execute(request,responseCallback);
}
 
开发者ID:aliyun,项目名称:HiTSDB-Client,代码行数:20,代码来源:HttpClient.java

示例2: executePostJsonStreamingResponse

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
private HttpStreamResponse executePostJsonStreamingResponse(HttpEntityEnclosingRequestBase requestBase,
    String jsonBody,
    Map<String, String> headers) throws HttpClientException {
    try {
        setRequestHeaders(headers, requestBase);
        requestBase.setEntity(new StringEntity(jsonBody, ContentType.APPLICATION_JSON));
        requestBase.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON);
        return executeStream(requestBase);
    } catch (IOException | UnsupportedCharsetException | OAuthCommunicationException | OAuthExpectationFailedException |
        OAuthMessageSignerException e) {
        String trimmedMethodBody = (jsonBody.length() > JSON_POST_LOG_LENGTH_LIMIT)
            ? jsonBody.substring(0, JSON_POST_LOG_LENGTH_LIMIT) : jsonBody;
        throw new HttpClientException("Error executing " + requestBase.getMethod() + " request " +
            "to " + clientPathToString(requestBase.getURI().getPath()) + " body:" + trimmedMethodBody, e);
    }
}
 
开发者ID:jivesoftware,项目名称:routing-bird,代码行数:17,代码来源:ApacheHttpClient441BackedHttpClient.java

示例3: addEntity

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
private void addEntity ( HttpEntityEnclosingRequestBase req, String contentType, byte[] o )
{
	final ByteArrayEntity input = new ByteArrayEntity ( o );
	input.setContentType ( contentType );
	req.addHeader ( "Content-Type", contentType );
	req.setEntity ( input );
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:8,代码来源:HttpClient.java

示例4: sendRequest

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
private HttpExampleResponse sendRequest(HttpEntityEnclosingRequestBase request, String data) {
    try {
        request.setEntity(new StringEntity(data));
        request.addHeader(Headers.CONTENT_TYPE, "application/json");
        return sendRequest(request);
    } catch (UnsupportedEncodingException e) {
        logException(e);

        throw new RuntimeException(e);
    }
}
 
开发者ID:Nearsoft,项目名称:android-school,代码行数:12,代码来源:ApacheHttpClientTransport.java

示例5: execute

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Override
public void execute() throws MojoExecutionException, MojoFailureException {

  try {
    ObjectMapper mapper = new ObjectMapper();
    String json = mapper.writeValueAsString(getPayload());

    //
    HttpEntityEnclosingRequestBase req = createHttpRequest();
    req.addHeader("consumer_key", consumerKey);
    req.addHeader("consumer_token", consumerToken);
    req.addHeader("Content-Type", "application/json");
    req.addHeader("Accept", "application/json");
    req.setEntity(new StringEntity(json));

    //
    CloseableHttpClient client = HttpClientBuilder.create().build();
    CloseableHttpResponse resp = client.execute(req);
    int statusCode = resp.getStatusLine().getStatusCode();
    try(InputStream in = resp.getEntity().getContent()) {
      Map<String, ?> sdkmanResp = (Map<String, ?>) mapper.readValue(in, Map.class);
      for (Map.Entry<String, ?> prop : sdkmanResp.entrySet()) {
        System.out.println(prop.getKey() + ":" + prop.getValue());
      }
    }
    if (statusCode < 200 || statusCode >= 300) {
      throw new Exception("Server returned error " + resp.getStatusLine());
    }
  } catch (Exception e) {
    throw new MojoExecutionException("Release failed", e);
  }
}
 
开发者ID:sdkman,项目名称:sdkman-vendor-maven-plugin,代码行数:33,代码来源:BaseMojo.java

示例6: addBodyToRequest

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
private void addBodyToRequest(HttpEntityEnclosingRequestBase request) {
    if (this.mRequestBody.equals(""))
        return;

    try {
        StringEntity se = new StringEntity(this.mRequestBody);
        se.setContentType(this.mRequestContentType);

        request.setEntity(se);
        request.addHeader("Content-Type", this.mRequestContentType);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
}
 
开发者ID:KsyMC,项目名称:ForgePE,代码行数:15,代码来源:HTTPRequest.java

示例7: request

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
public static <T> T request(String url, Header[] headers, Map<String, String> data, Function<CloseableHttpResponse, T> res)
		throws Exception {

	T rslt = null;
	CloseableHttpResponse response = null;
	CloseableHttpClient httpclient = null;

	// 시작 쿠키관리
	List<Cookie> cookies = cookieStore.getCookies();
	LOGGER.debug("Get cookies...  : " + cookies);

	try {

		HttpEntityEnclosingRequestBase http = new HttpPost(url);
		LOGGER.debug(url);

		if (headers != null) {
			for (Header header : headers) {
				if (header == null)
					continue;
				http.addHeader(header);
			}
		}

		httpclient = HttpClientBuilder.create().setDefaultCookieStore(cookieStore).build();
		// httpclient = HttpClients.createDefault();

		// 시작 서버로 보낼 데이터를 묶음.

		List<NameValuePair> dataArr = new ArrayList<NameValuePair>();

		if (ValueUtil.isNotEmpty(data)) {
			Iterator<String> iterator = data.keySet().iterator();
			while (iterator.hasNext()) {
				String key = iterator.next();
				String value = data.get(key);
				dataArr.add(new BasicNameValuePair(key, value));
			}

		}

		UrlEncodedFormEntity sendEntityData = new UrlEncodedFormEntity(dataArr, "UTF-8");
		http.setEntity(sendEntityData);
		// 끝 서버로 보낼 데이터를 묶음.

		/* 프록시 체크 */
		// if (USE_PROXY) {
		// HttpHost proxy = new HttpHost(PROXY_URL, PROXY_PORT, "http");
		// response = httpclient.execute(proxy, http);
		// }
		// else {
		response = httpclient.execute(http);
		// }

		rslt = res.apply(response);

	} finally {

		if (response != null)
			EntityUtils.consume(response.getEntity());

		if (httpclient != null) {
			httpclient.close();
		}

	}

	return rslt;

}
 
开发者ID:callakrsos,项目名称:Gargoyle,代码行数:71,代码来源:RequestUtil.java

示例8: put

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
@Override
public URI put(final WebResource resource, final boolean asBinary) {
    init.await();
    HttpEntityEnclosingRequestBase request = null;

    if (resource.uri() == null || !resource.uri().isAbsolute()) {
        request = new HttpPost(containerId);
        final String name = slugText(resource);
        if (name != null) {
            request.addHeader("Slug", name);
        }

        if (asBinary) {
            request.addHeader("Content-Disposition",
                    String.format("attachment; filename=%s", name != null ? name : "file.bin"));
        }

    } else {
        request = new HttpPut(resource.uri());
        if (!asBinary) {
            request.addHeader("Prefer", "handling=lenient; received=\"minimal\"");
        }
    }

    if (resource.representation() != null) {
        request.setEntity(new InputStreamEntity(resource.representation()));
    }
    request.setHeader(HttpHeaders.CONTENT_TYPE, resource.contentType());

    try {
        return client.execute(request, (response -> {
            final int status = response.getStatusLine().getStatusCode();

            if (status == HttpStatus.SC_CREATED) {
                return URI.create(response.getFirstHeader(HttpHeaders.LOCATION).getValue());
            } else if (status == HttpStatus.SC_NO_CONTENT || status == HttpStatus.SC_OK) {
                return resource.uri();
            } else {
                throw new RuntimeException(String.format("Resource creation failed: %s; %s",
                        response.getStatusLine().toString(),
                        EntityUtils.toString(response.getEntity())));
            }
        }));
    } catch (final Exception e) {
        throw new RuntimeException(String.format("Error executing %s request to %s", request.getClass()
                .getSimpleName(), request.getURI().toString()), e);
    }

}
 
开发者ID:fcrepo4-labs,项目名称:fcrepo-api-x,代码行数:50,代码来源:LdpContainerRegistry.java

示例9: addHeaders

import org.apache.http.client.methods.HttpEntityEnclosingRequestBase; //导入方法依赖的package包/类
private static void addHeaders(HttpEntityEnclosingRequestBase request) {
	request.addHeader("User-Agent", USER_AGENT);
	request.addHeader("accept", "application/json");
}
 
开发者ID:clicksign,项目名称:clicksign-java,代码行数:5,代码来源:ClicksignResource.java


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