野兽

java模拟post提交

java通过http协议模拟post提交

代码:     URL url=new URL("");

     OutputStreamWriter outStrm =null;
     URLConnection rulConnection = url.openConnection();
     HttpURLConnection httpUrlConnection = (HttpURLConnection) rulConnection;
       httpUrlConnection.setDoOutput(true);
       httpUrlConnection.setDoInput(true);
       httpUrlConnection.setUseCaches(false);
       httpUrlConnection.setRequestMethod("POST");
       httpUrlConnection.setRequestProperty("accept", "*/*");

outStrm= new OutputStreamWriter(httpUrlConnection
         .getOutputStream()); //提交数据
       outStrm.flush();
       outStrm.write(param);
       outStrm.close();
       InputStream inStrm = httpUrlConnection.getInputStream();//从服务器返回的数据

BufferedReader br = new BufferedReader(new InputStreamReader(inStrm,"UTF-8"));

posted @ 2012-11-18 16:10  android-susu  阅读(292)  评论(0编辑  收藏  举报