HttpClient触发HTTP请求

      public static void main(String[] args) {
        try {
            //设置HTTP请求参数
            HttpClient client = new HttpClient();
            client.getParams().setConnectionManagerTimeout(com.jd.lottery.domain.communicate.wzl.WZLConstants.CONNECT_TIMEOUT);  //连接超时时间
            client.getHttpConnectionManager().getParams().setIntParameter(
                    HttpMethodParams.BUFFER_WARN_TRIGGER_LIMIT, 2 * 1024 * 1024);
            client.getHttpConnectionManager().getParams().setReceiveBufferSize(2 * 1024 * 1024);
            PostMethod method = new PostMethod("
http://caipiao.360buy.net/api/wzl/receive.action "); //这里绝对不可以写成 http://caipiao.360buy.net/api/wzl/receive.action/
            method.getParams().setSoTimeout(com.jd.lottery.domain.communicate.wzl.WZLConstants.GET_DATA_TIMEOUT); //数据处理时间,超时则交易断开
            method.getParams().setContentCharset(com.jd.lottery.domain.communicate.wzl.WZLConstants.CHARSET);
            method.setRequestHeader("Cache-Control", "no-cache");
//            method.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");//键值对传输   request.getParameter接收(接收方)
//            method.setRequestHeader("Content-Type", "text/html");//纯文本传输      request.getInputStream接收 (接收方)
            method.setRequestHeader("Content-Type", "multipart/form-data");//type=file方式传输    request.getInputStream接收 (接收方)
            method.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, new DefaultHttpMethodRetryHandler(com.jd.lottery.domain.communicate.wzl.WZLConstants.RETRY_COUNT, false));
            NameValuePair[] postData = new NameValuePair[2];
            postData[0] = new NameValuePair("cmd", "1000");
            postData[1] = new NameValuePair("msg", "aaaaaaaaaaaaaaa");
            method.addParameters(postData);
            client.executeMethod(method);
            System.out.println(method.getStatusCode());
            System.out.println(method.getResponseBodyAsString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

你可能感兴趣的:(exception,String,cmd,File,360)