jfy3d(剑事)BLOG

  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  37 随笔 :: 0 文章 :: 363 评论 :: 0 Trackbacks

param 为aaa=111&bbb=222.....格式

-------------------------------------------------
public static String sendGet(String url,String param)
 {
  String result = "";
  try{
   String urlName = url + "?"+param;//

   URL U = new URL(urlName);
   URLConnection connection = U.openConnection();
   connection.connect();
  
   BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
   String line;
   while ((line = in.readLine())!= null)
   {
    result += line;
   }
   in.close();   
  }catch(Exception e){
   System.out.println("没有结果!"+e);
  }
  return result;
 }
 
 public static String sendPost(String url,String param)
 {
  String result="";
  try{
   URL httpurl = new URL(url);
   HttpURLConnection httpConn = (HttpURLConnection)httpurl.openConnection();      
   httpConn.setDoOutput(true);
   httpConn.setDoInput(true);
   PrintWriter out = new PrintWriter(httpConn.getOutputStream());
   out.print(param);
   out.flush();
   out.close();
   BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
   String line;
   while ((line = in.readLine())!= null)
   {
    result += line;
   }
   in.close();
  }catch(Exception e){
   System.out.println("没有结果!"+e);
  }
  return result;
 }

posted on 2005-05-11 15:37 剑事 阅读(9587) 评论(0)  编辑  收藏 所属分类: 小程序

只有注册用户登录后才能发表评论。


网站导航: