惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Engineering at Meta
Engineering at Meta
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
博客园_首页
T
Tailwind CSS Blog
美团技术团队
博客园 - 叶小钗
Microsoft Security Blog
Microsoft Security Blog
有赞技术团队
有赞技术团队
Apple Machine Learning Research
Apple Machine Learning Research
大猫的无限游戏
大猫的无限游戏
Microsoft Azure Blog
Microsoft Azure Blog
H
Hackread – Cybersecurity News, Data Breaches, AI and More
I
InfoQ
MongoDB | Blog
MongoDB | Blog
The Cloudflare Blog
J
Java Code Geeks
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园 - 聂微东
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Y
Y Combinator Blog

博客园 - 南郭先生kaka

待处理数据的两种模型 nginx重启无法找到PId的解决办法 Wiki版产品需求---产品需求文档到底是谁的?产品到底是谁的? 为什么说private方法是有罪的 XML2JSON 的【net.sf.json.JSONException: nu.xom.ParsingException must be followed by either attribute specifications, ">" or "/>"】问题解决办法 继承的第一原则 致那些不甘寂寞的人 上传File时,浏览器总是添加<pre>的解决办法 使用XSLT转换XML2XML WITH AS SQL语句的用法 【Code Style】多余判断 java.lang.NoClassDefFoundError错误 Spring 中Quartz配置数据库化 FactoryBean在XML中的依赖注入方法 Camel FTP中文目录解决办法 配置CentOS6.3 NFS Bean复制的几种框架性能比较(Apache BeanUtils、PropertyUtils,Spring BeanUtils,Cglib BeanCopier) 重读《目标》---目标 重读《目标》---序
Java 模拟 Http Post
南郭先生kaka · 2013-05-15 · via 博客园 - 南郭先生kaka

     因为某些原因,需要模拟Http post,向服务器进行提交数据。自己琢磨了很多种方法,什么ajax模拟,什么注入啊,想想都太高级了,自己也不太懂,于是想了想,咱也是java程序员,还是找个java的,这样应用起来也是得心应手了。于是施展了baidu和google大法,直接找到了一个开箱即用的模拟方法。我进行了简单的修改。具体代码如下:

 1 public class HttpPostSimulator {
 2     public static void post() throws IOException {
 3 
 4         URL url = new URL("http://a.b.com/dda/updateCCC.action");
 5         URLConnection connection = url.openConnection();
 6         connection.setDoOutput(true);
 7         OutputStreamWriter out = new OutputStreamWriter(
 8                 connection.getOutputStream(), "utf-8");
 9         
10         // post的数据
11         out.write("s.code=de0947&s.typeCode=ccc"); 
12 // 向页面传递数据。post的关键所在!
13         out.flush();
14         out.close();
15         
16         // 一旦发送成功,用以下方法就可以得到服务器的回应:
17         String sCurrentLine;
18         String sTotalString;
19         sCurrentLine = "";
20         sTotalString = "";
21         // 传说中的三层包装阿!
22         BufferedReader resultReader = new BufferedReader(new InputStreamReader(
23                 connection.getInputStream()));
24         while ((sCurrentLine = resultReader.readLine()) != null) {
25             sTotalString += sCurrentLine + "\r\n";
26 
27         }
28         System.out.println(sTotalString);
29 
30     }
31 
32     public static void main(String[] args) throws IOException {
33         post();
34     }
35 }

   参考的地址: 

Java模拟Post 提交表单数据

http://blog.csdn.net/kalision/article/details/7920908