當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpPost.abort方法代碼示例

本文整理匯總了Java中org.apache.http.client.methods.HttpPost.abort方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpPost.abort方法的具體用法?Java HttpPost.abort怎麽用?Java HttpPost.abort使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.client.methods.HttpPost的用法示例。


在下文中一共展示了HttpPost.abort方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doPost

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
public String doPost(String url, List<NameValuePair> pairs, String charset) {
    if (StringUtils.isBlank(url)) {
        return null;
    }
    log.info(" post url=" + url);
    try {
        HttpPost httpPost = new HttpPost(url);
        if (pairs != null && pairs.size() > 0) {
            httpPost.setEntity(new UrlEncodedFormEntity(pairs, charset));
        }
        CloseableHttpResponse response = httpClient.execute(httpPost);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            httpPost.abort();
            throw new RuntimeException("HttpClient,error status code :" + statusCode);
        }
        HttpEntity entity = response.getEntity();
        String result = null;
        if (entity != null) {
            result = EntityUtils.toString(entity, charset);
        }
        EntityUtils.consume(entity);
        response.close();
        return result;
    } catch (Exception e) {
        log.error("to request addr=" + url + ", " + e.getMessage());
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:31,代碼來源:HttpHelper.java

示例2: doPostLongWait

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
public String doPostLongWait(String url, List<NameValuePair> pairs, String charset) {
    if (StringUtils.isBlank(url)) {
        return null;
    }
    log.info(" post url=" + url);
    try {
        RequestConfig requestConfig = RequestConfig.custom()
                .setSocketTimeout(300000)
                .setConnectTimeout(30000).build();
        HttpPost httpPost = new HttpPost(url);
        httpPost.setConfig(requestConfig);
        if (pairs != null && pairs.size() > 0) {
            httpPost.setEntity(new UrlEncodedFormEntity(pairs, charset));
        }
        CloseableHttpResponse response = httpClient.execute(httpPost);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            httpPost.abort();
            throw new RuntimeException("HttpClient,error status code :" + statusCode);
        }
        HttpEntity entity = response.getEntity();
        String result = null;
        if (entity != null) {
            result = EntityUtils.toString(entity, charset);
        }
        EntityUtils.consume(entity);
        response.close();
        return result;
    } catch (Exception e) {
        log.error("to request addr=" + url + ", " + e.getMessage());
        e.printStackTrace();
    }
    return null;
}
 
開發者ID:Zephery,項目名稱:newblog,代碼行數:35,代碼來源:HttpHelper.java

示例3: doPost

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
/**
 * HTTP Post 獲取內容
 *
 * @param url     請求的url地址 ?之前的地址
 * @param params  請求的參數
 * @param charset 編碼格式
 * @return 頁麵內容
 */
public static String doPost(String url, Map<String, String> params, String charset) throws Exception {
    if (StringUtils.isBlank(url)) {
        return null;
    }
    try {
        List<NameValuePair> pairs = null;
        if (params != null && !params.isEmpty()) {
            pairs = new ArrayList<>(params.size());
            //去掉NameValuePair轉換,這樣就可以傳遞Map<String,Object>
            /*pairs = new ArrayList<NameValuePair>(params.size());*/
            for (Map.Entry<String, String> entry : params.entrySet()) {
                String value = entry.getValue();
                if (value != null) {
                    pairs.add(new BasicNameValuePair(entry.getKey(), value));
                }
            }
        }
        HttpPost httpPost = new HttpPost(url);
        if (pairs != null && pairs.size() > 0) {
            httpPost.setEntity(new UrlEncodedFormEntity(pairs, CHARSET));
        }
        CloseableHttpResponse response = httpClient.execute(httpPost);
        int statusCode = response.getStatusLine().getStatusCode();
        if (statusCode != 200) {
            httpPost.abort();
            throw new RuntimeException("HttpClient,error status code :" + statusCode);
        }
        HttpEntity entity = response.getEntity();
        String result = null;
        if (entity != null) {
            result = EntityUtils.toString(entity, "utf-8");
        }
        EntityUtils.consume(entity);
        response.close();
        return result;
    } catch (Exception e) {
        throw e;
    }
}
 
開發者ID:fanqinghui,項目名稱:wish-pay,代碼行數:48,代碼來源:HttpClientUtils.java

示例4: close

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
public void close() throws IOException {
    HttpPost request = this.request;
    if (request != null) {
        request.abort();
    }
}
 
開發者ID:dachengxi,項目名稱:EatDubbo,代碼行數:7,代碼來源:HttpClientConnection.java

示例5: sendPost

import org.apache.http.client.methods.HttpPost; //導入方法依賴的package包/類
public String sendPost(String url, String xmlObj) throws IOException, KeyStoreException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyManagementException {

        if (!hasInit) {
            init();
        }

        String result = null;

        HttpPost httpPost = new HttpPost(url);

        //得指明使用UTF-8編碼,否則到API服務器XML的中文不能被成功識別
        StringEntity postEntity = new StringEntity(xmlObj, "UTF-8");
        httpPost.addHeader("Content-Type", "text/xml");
        httpPost.setEntity(postEntity);

        //設置請求器的配置
        httpPost.setConfig(requestConfig);

        try {
            HttpResponse response = httpClient.execute(httpPost);

            HttpEntity entity = response.getEntity();

            result = EntityUtils.toString(entity, "UTF-8");

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            httpPost.abort();
        }

        return result;
    }
 
開發者ID:1991wangliang,項目名稱:pay,代碼行數:35,代碼來源:HttpsRequest.java


注:本文中的org.apache.http.client.methods.HttpPost.abort方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。