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


Java HttpPost.setHeaders方法代码示例

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


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

示例1: executeRequest

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
/**
 * Sends a POST request to the service at {@code serviceUrl} with a payload of {@code request}.
 * The request type is determined by the {@code headers} param.
 *
 * @param request    A {@link String} representation of a request object. Can be JSON object, form data, etc...
 * @param serviceUrl The service URL to sent the request to
 * @param headers    An array of {@link Header} objects, used to determine the request type
 * @return {@link String} response from the service (representing JSON object)
 * @throws IOException if the connection is interrupted or the response is unparsable
 */
public String executeRequest(String request, String serviceUrl, Header[] headers) throws IOException {
    HttpPost httpPost = new HttpPost(serviceUrl);
    httpPost.setHeaders(headers);
    httpPost.setEntity(new StringEntity(request, Charset.forName("UTF-8")));

    if (logger.isDebugEnabled()) {
        logger.debug("Sent " + request);
    }

    HttpResponse response = httpClient.execute(httpPost);

    String responseJSON = EntityUtils.toString(response.getEntity(), UTF8_CHARSET);
    if (logger.isDebugEnabled()) {
        logger.debug("Received " + responseJSON);
    }
    return responseJSON;
}
 
开发者ID:SafeChargeInternational,项目名称:safecharge-java,代码行数:28,代码来源:SafechargeRequestExecutor.java

示例2: HttpPost

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
private boolean b044C044C044Cьь044C(String str, String str2, String str3, String str4) throws ClientProtocolException, IOException {
    this.b041BЛЛ041BЛ041B = b044Cьь044Cь044C(str3);
    HttpPost httpPost = new HttpPost(bЛ041BЛЛЛ041B);
    String generateSignature = new crrcrc().generateSignature(str2, this.b041BЛЛ041BЛ041B, str4);
    httpPost.setEntity(new StringEntity(str4, "UTF-8"));
    httpPost.setHeaders(this.b041BЛЛ041BЛ041B);
    Object bььь044Cь044C = bььь044Cь044C(str, generateSignature, httpPost);
    HttpResponse execute = new DefaultHttpClient().execute(bььь044Cь044C);
    Log.d(b041BЛЛЛЛ041B, "All POST request headers:");
    for (Header header : bььь044Cь044C.getAllHeaders()) {
        Log.d(b041BЛЛЛЛ041B, header.getName() + NetworkUtils.DELIMITER_COLON + header.getValue());
    }
    Log.d(b041BЛЛЛЛ041B, "HTTP Request body: " + str4);
    String str5 = b041BЛЛЛЛ041B;
    StringBuilder append = new StringBuilder().append("HTTP Response: ");
    StatusLine statusLine = execute.getStatusLine();
    int b0427ЧЧЧ0427Ч = b0427ЧЧЧ0427Ч();
    switch ((b0427ЧЧЧ0427Ч * (b04270427ЧЧ0427Ч + b0427ЧЧЧ0427Ч)) % bЧЧ0427Ч0427Ч) {
        case 0:
            break;
        default:
            b0427Ч0427Ч0427Ч = b0427ЧЧЧ0427Ч();
            bЧ0427ЧЧ0427Ч = b0427ЧЧЧ0427Ч();
            break;
    }
    Log.d(str5, append.append(statusLine.toString()).toString());
    Log.d(b041BЛЛЛЛ041B, "HTTP Response: " + EntityUtils.toString(execute.getEntity()));
    return execute.getStatusLine().getStatusCode() == 200;
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:30,代码来源:rcccrr.java

示例3: connect

import org.apache.http.client.methods.HttpPost; //导入方法依赖的package包/类
/**
 * Prepares the post transport.
 * 
 * @param bidrequest
 *            the request to send
 * @param header
 *            to fill in connection header
 * @return the body result from the response
 * @throws BidProcessingException
 */
String connect(final String bidrequest, final Header[] header) throws BidProcessingException {
	final HttpPost httpPost = new HttpPost(endpoint);
	httpPost.setHeaders(header);
	return jsonPostConnector.connect(new StringEntity(bidrequest, ContentType.APPLICATION_JSON), httpPost);
}
 
开发者ID:ad-tech-group,项目名称:openssp,代码行数:16,代码来源:OpenRtbConnector.java


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