package cn.song.kotlind.net

import java.io.BufferedInputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import java.net.HttpURLConnection
import java.net.URL

/**
 * @author hzsongzhengwang
 * @date 2015/7/14
 * Copyright 2015 Six. All rights reserved.
 */

class BaseRequest(getUrl : String){
    val url = getUrl;

    fun sendRequest() : String?{
        var urlObj = URL(url)
        var http = urlObj.openConnection() as HttpURLConnection
        if(http.getResponseCode() == HttpURLConnection.HTTP_OK){
            var stream = BufferedInputStream(http.getInputStream())
            var reader = BufferedReader(InputStreamReader(stream))
            val sb = StringBuilder()
            reader.forEachLine { sb.append(it) }
            return sb.toString();
        }
        http.disconnect();

        return null;
    }
}