简单的java post 数据
时间:2010-07-18 来源:pk3589
package test; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.BufferedWriter; import java.io.FileWriter; import java.io.InputStreamReader; import java.io.OutputStreamWriter; import java.net.URL; import java.net.URLConnection; public class JavaPostTest { public String post() throws Exception{ URL url = new URL("http://www.renren.com/PLogin.do"); URLConnection conn = url.openConnection(); conn.setDoOutput(true); OutputStreamWriter writer = new OutputStreamWriter(conn.getOutputStream()); writer.write("[email protected]&password=123"); writer.flush(); writer.close(); InputStreamReader reder = new InputStreamReader(conn.getInputStream(),"utf-8"); BufferedReader breader = new BufferedReader(reder); BufferedWriter w = new BufferedWriter(new FileWriter("d:/1.txt")); String content = null; String result = null; while((content=breader.readLine())!=null){ result+=content+"\n"; } w.write(result); w.flush(); w.close(); return result; } public static void main(String[] args) throws Exception{ JavaPostTest post = new JavaPostTest(); String aa = post.post(); String bb = new String(aa.getBytes("utf-8")); System.out.println(bb); } }
相关阅读 更多 +