當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。