Simulate Http Post in Java

Source: Internet
Author: User

For some reason, you need to simulate Http post and submit data to the server. I have learned many ways, such as ajax simulation and injection. I think it's too advanced and I don't know much about it. So I thought about it. I am also a java programmer, find a java app. Therefore, the baidu and google methods were used to directly find an out-of-the-box simulation method. I made a simple modification. The Code is as follows:

1 public class HttpPostSimulator {2 public static void post () throws IOException {3 4 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 Data 11 out. write ("s. code = de0947 & s. typeCode = ccc "); 12 // pass data to the page. The key to post! 13 out. flush (); 14 out. close (); 15 16 // once the message is sent successfully, use the following method to get the server response: 17 String sCurrentLine; 18 String sTotalString; 19 sCurrentLine = ""; 20 sTotalString = ""; 21 // The legendary Three-tier package! 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}

Reference address:

Simulate Post submission form data using Java

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.