web

来源:互联网 发布:单机版考试软件 编辑:程序博客网 时间:2024/05/29 17:05
  1. import gov.hn12396.appintegration.mule.util.EncoderUtil;  
  2.   
  3. import java.io.IOException;  
  4. import java.io.InputStream;  
  5. import java.io.OutputStream;  
  6. import java.net.HttpURLConnection;  
  7. import java.net.URL;  
  8. import java.util.Calendar;  
  9. /** 
  10.  * 模拟浏览器通过发送http请求,调用应用集成平台的mail协议,发送电子邮件 
  11.  * @author liuxp 
  12.  * 
  13.  */  
  14. public class MailTestClient {  
  15.     /** 
  16.      * 保存应用集成平台暴露给其他应用程序调用的地址 
  17.      */  
  18. //  private static String Mail_URI = "http://localhost:8082/email/?";  
  19.     private static String Mail_URI = "http://10.2.11.40:8082/email/?";  
  20.   
  21.     /** 
  22.      * 读取http请求的信息 
  23.      * @throws IOException 
  24.      */  
  25.     public static void readHttpFromMail() throws IOException {  
  26.         StringBuffer bufUrl = new StringBuffer(Mail_URI);  
  27.         bufUrl.append("email=328172228@qq.com&cc=liuxp@surekam.com&subject=dd&text=998打算发放");  
  28.         URL url = new URL(bufUrl.toString()); // 设置请求的链接  
  29.         HttpURLConnection conn = (HttpURLConnection) url.openConnection();  
  30. //      System.out.println(conn.getResponseCode()); // 查看响应状态码  
  31. //      System.out.println(conn.getHeaderField("Content-Length")); // 响应文本内容的长度  
  32. //      System.out.println(conn.getContentEncoding()); // 响应文本内容的编码  
  33.         InputStream in = conn.getInputStream(); // 获取一个和服务器返回的内容相关联的流  
  34.         try {  
  35.             int len = 0;  
  36.             byte[] buffer = new byte[1024];  
  37.             while ((len = in.read(buffer)) > 0) {  
  38.                 System.out.println(new String(buffer, 0, len)); // 输出到控制台  
  39.             }  
  40.         } finally {  
  41.             if (in != null)  
  42.                 try {  
  43.                     in.close();  
  44.                 } catch (Exception e) {  
  45.                     e.printStackTrace();  
  46.                 }  
  47.         }  
  48.     }  
  49.     public static void main(String[] args) throws IOException {  
  50.         readHttpFromMail();  
  51. //      sendHttpToJDBC();StringToEmailMessage  
  52.     }  
  53. }  
0 0