Url GET POST

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();

        }
    }

}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值