zoukankan      html  css  js  c++  java
  • 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;

    }

    }

    看不清未来,就做好现在,,,
  • 相关阅读:
    Spring static 静态属性注入
    大众点评Cat--架构分析
    rxjava
    TCP/IP协议三次握手与四次握手流程解析
    [SDOI2014]数数
    CF-GYM101741K. Consistent Occurrences
    [JSOI2012]玄武密码
    [POI2000]病毒
    [JSOI2007]文本生成器
    [HNOI2006]最短母串问题
  • 原文地址:https://www.cnblogs.com/gsdimz/p/3089918.html
Copyright © 2011-2022 走看看