• HttpClientAdapter1(工具类)


    package com.ithm.lottery16.net;

    import java.io.InputStream;

    import org.apache.commons.lang3.StringUtils;
    import org.apache.http.HttpHost;
    import org.apache.http.HttpRequest;
    import org.apache.http.HttpResponse;
    import org.apache.http.client.HttpClient;
    import org.apache.http.client.methods.HttpGet;
    import org.apache.http.client.methods.HttpPost;
    import org.apache.http.conn.params.ConnRoutePNames;
    import org.apache.http.entity.StringEntity;
    import org.apache.http.impl.client.DefaultHttpClient;

    import com.ithm.lottery16.ConstantValue;
    import com.ithm.lottery16.GloableParams;

    public class HttpClientAdapter {
    private HttpClient client;

    private HttpRequest request;

    private HttpGet get;
    private HttpPost post;

    private HttpResponse response;


    public HttpClientAdapter()
    {
    client=new DefaultHttpClient();
    if(StringUtils.isNotBlank(GloableParams.PROXY_IP))
    {
    //wap方式
    HttpHost host=new HttpHost(GloableParams.PROXY_IP, GloableParams.PROXY_PORT);
    client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, host);
    }
    }

    public InputStream sendXml(String url, String xml) {
    post = new HttpPost(url);
    StringEntity entity;
    try {
    entity = new StringEntity(xml, ConstantValue.CHARSET);
    post.setEntity(entity);

    response = client.execute(post);

    if (response.getStatusLine().getStatusCode() == 200) {
    return response.getEntity().getContent();
    }

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

    return null;

    }

    }

    看不清未来,就做好现在,,,
  • 相关阅读:
    【转】 Ubuntu安装jdk报错:-bash /usr/.../java:No such file or directroy
    sudo 出现unable to resolve host 解决方法
    C99 布尔
    面向对象?
    高斯消元
    白皮 Chapter 2
    白皮 Chapter 1
    开启暑假新生活( •̀ ω •́ )
    [vijos P1040] 高精度乘法
    [SCOI2007] 修车
  • 原文地址:https://www.cnblogs.com/gsdimz/p/3089918.html
Copyright © 2020-2023  润新知