当前位置: 首页>>代码示例>>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;未经允许,请勿转载。