package com.qq;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLEncoder;

import org.omg.CORBA.portable.OutputStream;

import sun.net.www.URLConnection;
import sun.net.www.http.HttpClient;

import java.net.URLDecoder;
import java.io.UnsupportedEncodingException;

public class PostRequest 
{
	public static void main(String[] args) throws Exception 
	{
		
		String pathUrl = "http://localhost:8080/IbotInfo/GetInfo";  
		String sendInfo="346786495@qq.com";
		String recieveInfo="wnbupt@qq.com";
		String timeInfo="2015-12-16-10:43";
		String subjectInfo="����demo������";
		String bodyInfo="������ʵҲ�ǿ��Ե��������";
		String[] appendInfo={"D:/ibotest/test.ppt","D:/ibotest/test.doc"};
		//String[] appendInfo={"null"};//û�и�����ʱ����null
		
		String sender=URLEncoder.encode(sendInfo,"UTF-8");  
        String reciever=URLEncoder.encode(recieveInfo,"UTF-8"); 
        String sendtime=URLEncoder.encode(timeInfo,"UTF-8"); 
        String subject=URLEncoder.encode(subjectInfo,"UTF-8"); 
        String body=URLEncoder.encode(bodyInfo,"UTF-8");   
        String sendMsg=("sender="+sender+"&reciever="+reciever+"&sendtime="+sendtime+"&subject="+subject+"&body="+body+"&attachment=");
        int i;
        for(i=0;i<appendInfo.length-1;i++)
        {
        	appendInfo[i]=URLEncoder.encode(appendInfo[i],"UTF-8");
        	sendMsg=sendMsg+appendInfo[i]+"|";
        }
        appendInfo[i]=URLEncoder.encode(appendInfo[i],"UTF-8");
    	sendMsg=sendMsg+appendInfo[i];	 
		//System.out.println(sendMsg);
		// ��������   
		URL url = new URL(pathUrl);
        HttpURLConnection conn = (HttpURLConnection) url.openConnection();
        conn.setDoOutput(true);    // ���Է�������
        conn.setDoInput(true);    // ���Խ�������
        conn.setRequestMethod("POST");    // POST����
        conn.setRequestProperty
        ("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0)");
        conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");       
        conn.connect();
        //    д���POST����  
        OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream());       
        
		
        
        
        
               
        osw.write(sendMsg);
        osw.flush();
        osw.close();
        // ��ȡ��Ӧ����
        
        BufferedReader reader = null;
	    StringBuffer sbf = new StringBuffer();	
        java.io.InputStream is = conn.getInputStream();
        //InputStream is = (InputStream) connection.getInputStream();
        reader = new BufferedReader(new InputStreamReader(is,"utf-8"));
        String strRead = null;
        while ((strRead = reader.readLine()) != null) {
        	//System.out.println(strRead);
            sbf.append(strRead);
            sbf.append("\r\n");
        }
        reader.close();
        System.out.println(sbf);
    }
}


@@ -804,22 +804,17 @@
 fo=%22
-%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BDdemo%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD
+%E6%B5%8B%E8%AF%95demo%E8%B7%91%E8%B5%B7%E6%9D%A5
 %22;%0D%0A
@@ -836,30 +836,22 @@
 fo=%22
-%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%CA%B5%D2%B2%EF%BF%BD%C7%BF%EF%BF%BD%EF%BF%BD%D4%B5%EF%BF%BD%EF%BF%BD%EF%A3%A1%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD
+%E4%B8%AD%E6%96%87%E5%85%B6%E5%AE%9E%E4%B9%9F%E6%98%AF%E5%8F%AF%E4%BB%A5%E7%9A%84%E5%98%9B%EF%BC%81%EF%BC%81%E7%82%B9%E8%B5%9E
 %22;%0D%0A
@@ -957,27 +957,8 @@
 l%22%7D;
-//%C3%BB%EF%BF%BD%D0%B8%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%CA%B1%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BDnull
 %0D%0A%09%09
@@ -1742,24 +1742,8 @@
 );%0D%0A
-%09%09// %EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD   
 %0D%0A%09%09
@@ -1885,23 +1885,8 @@
 ;   
- // %EF%BF%BD%EF%BF%BD%EF%BF%BD%D4%B7%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD
 %0D%0A  
@@ -1921,22 +1921,8 @@
     
-// %EF%BF%BD%EF%BF%BD%EF%BF%BD%D4%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD
 %0D%0A  
@@ -1968,20 +1968,18 @@
  // POST
-%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD
+%E6%96%B9%E5%BC%8F
 %0D%0A      
@@ -2215,28 +2215,8 @@
     
-//    %D0%B4%EF%BF%BD%EF%BF%BD%EF%BF%BDPOST%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD  
 %0D%0A  
@@ -2304,55 +2304,8 @@
     
-%0D%0A        %0D%0A%09%09%0D%0A        %0D%0A        %0D%0A        %0D%0A 
     
@@ -2399,25 +2399,8 @@
     
-  // %EF%BF%BD%EF%BF%BD%C8%A1%EF%BF%BD%EF%BF%BD%D3%A6%EF%BF%BD%EF%BF%BD%EF%BF%BD%EF%BF%BD%0D%0A
     

change little