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;

    }

    }

    看不清未来,就做好现在,,,
  • 相关阅读:
    第一个SpringBoot
    windows 安装 mysql 及部分命令
    别让猴子跳回背上
    windows环境下基于Anaconda安装Tensorflow
    spark
    ubuntu环境下安装chrome
    前言
    模型压缩(4)
    模型压缩(3)
    模型压缩(2)
  • 原文地址:https://www.cnblogs.com/gsdimz/p/3089918.html
Copyright © 2011-2022 走看看