java的post请求
package com.huazhu; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.util.List; import java.util.Map; public class httppost { public static void main(String[] args) { httppost send=new httppost(); send.sendpost("https://passport.cnblogs.com/user/signin", "input1":"=","input2":"
} public void sendpost(String urlAddess,String paramVaule) throws IOException { try { HttpURLConnection urlcon=null; URL url=new URL(urlAddess); urlcon=(HttpURLConnection) url.openConnection(); urlcon.setDoOutput(true); urlcon.setReadTimeout(5000); urlcon.setConnectTimeout(5000); urlcon.connect(); PrintWriter pw=new PrintWriter(urlcon.getOutputStream()); pw.print(paramVaule); pw.flush(); BufferedReader bf=new BufferedReader(new InputStreamReader(urlcon.getInputStream(),"utf-8")); String line=bf.readLine(); while(line!=null) { System.out.println(line); line=bf.readLine(); } Map<String,List<String>> map=urlcon.getHeaderFields(); List list=(List)map.get("Set-Cookie"); for(int i=0;i<list.size();i++) { System.out.println(list.get(i)); } } catch (MalformedURLException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }