梦幻之旅

DEBUG - 天道酬勤

   :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  671 随笔 :: 6 文章 :: 256 评论 :: 0 Trackbacks
package com.roadway.httpinterface.util;



import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Send_Url_Get {
    private String urlStr;

    private URL url;

    private HttpURLConnection url_con;

    private String contentStr;

    public void setUrlStr(String urlStr) {
        this.urlStr = urlStr;
    }

    public String getContentStr() {
        return contentStr;
    }

    private void setContentStr(String contentStr) {
        this.contentStr = contentStr;
    }

    public void send_url() {
        try {
            StringBuilder temp = new StringBuilder();

            url = new URL(urlStr);

            url_con = (HttpURLConnection) url.openConnection();
            url_con.setDoOutput(true);
            url_con.setRequestMethod("GET");

            url_con.getOutputStream().flush();
            url_con.getOutputStream().close();
            InputStream in = url_con.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(in));

            while (rd.ready()){
                temp.append(rd.readLine());
            }
            setContentStr(new String(temp));

        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            if (url_con != null) {
                url_con.disconnect();
            }
        }
    }

}


package com.roadway.httpinterface.util;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class Send_Url_Send {
    private String urlStr;
    private URL url;
    private HttpURLConnection url_con;
    private String response_content;


    public void setUrlStr(String urlStr) {
        this.urlStr = urlStr;
    }

    public String getResponse_content() {
        return response_content;
    }

    private  void setResponse_content(String response_content) {
        this.response_content = response_content;
    }

    public void send_url(String mobile_number){
        try{
            url = new URL(urlStr);
            url_con=(HttpURLConnection)url.openConnection();
            url_con.setRequestMethod("POST");
            url_con.setDoOutput(true);
            String param="action=mobile
&mobile="+mobile_number;
            
            url_con.getOutputStream().write(param.getBytes());
            url_con.getOutputStream().flush();
            url_con.getOutputStream().close();

            InputStream in= url_con.getInputStream();
            BufferedReader   rd = new BufferedReader(new InputStreamReader(in));
            StringBuilder tempStr=new StringBuilder();

            while (rd.ready()){
                tempStr.append(rd.readLine());
            }
           setResponse_content(new String(tempStr));
    } catch(Exception e){
            e.printStackTrace();
        }
        finally{
            if(url_con!=null)
            url_con.disconnect();

        }
    }

}
posted on 2009-08-20 17:18 HUIKK 阅读(756) 评论(0)  编辑  收藏 所属分类: Java

只有注册用户登录后才能发表评论。


网站导航: