/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package java_post;

import java.io.IOException;  
import java.io.InputStream;  
import java.io.OutputStreamWriter;  
import java.net.URL;  
import java.net.URLConnection;  
import java.util.logging.Level;  
import java.util.logging.Logger;  
import org.apache.commons.io.IOUtils;

/**
 *
 * @author ideacall
 */
public class Java_post {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        try{  
            // Configure and open a connection to the site you will send the request  
            URL url = new URL("http://10.101.23.173/watergroup/serv/gisapp/report.php");  
            URLConnection urlConnection = url.openConnection();  
            // 设置doOutput属性为true表示将使用此urlConnection写入数据  
            urlConnection.setDoOutput(true);  
            // 定义待写入数据的内容类型,我们设置为application/x-www-form-urlencoded类型  
            urlConnection.setRequestProperty("content-type", "application/x-www-form-urlencoded");  
            // 得到请求的输出流对象  
            OutputStreamWriter out = new OutputStreamWriter(urlConnection.getOutputStream());  
            // 把数据写入请求的Body  
            out.write("a=1");
            out.write("b=1");
            out.write("message = Hello World chszs");   
            out.flush();  
            out.close();  
              
            // 从服务器读取响应  
            InputStream inputStream = urlConnection.getInputStream();  
            String encoding = urlConnection.getContentEncoding();  
            String body = IOUtils.toString(inputStream, encoding);  
            System.out.println(body);  
        }catch(IOException e){  
            //Logger.getLogger(RequestTest.class.getName()).log(Level.SEVERE, null, e);  
        }          
    }
    
}