Http (Java) post and Get methods

Source: Internet
Author: User

Two ways to send post and get requests in Java

1.URL
2.httpclient

The first way:

Send request in URL form

The second way:
commons-httpclient-3.1.jar;
Import Org.apache.commons.httpclient.httpclient;import Org.apache.commons.httpclient.methods.postmethod;import        Org.apache.commons.httpclient.params.httpmethodparams;public class Test {public static void main (string[] args) {        String info = null;            try {HttpClient HttpClient = new HttpClient (); Postmethod post = new Postmethod ("http://192.168.11.11/sssssssss/ssAction!updateYunMasCallBack.action");//POS            T.getparams (). Setparameter (Httpmethodparams.http_content_charset, "GBK");            Post.addparameter ("Spcode", "sssssss");            Post.addparameter ("LoginName", "ssss");            Post.addparameter ("Password", "ssssss"); Post.addparameter ("Messagecontent", "You have an item numbered 23 you need to handle 56 of the transaction.            ");            Post.addparameter ("Usernumber", "15680805571");            Post.addparameter ("SerialNumber", "12345678901234567890");            Post.addparameter ("Scheduletime", "" ");            Post.addparameter ("Extendaccessnum", "" "); PoSt.addparameter ("F", "1");            Httpclient.executemethod (POST);            info = new String (Post.getresponsebody (), "GBK");        SYSTEM.OUT.PRINTLN (info);        } catch (Exception e) {e.printstacktrace (); }    }}

Http (Java) post and get methods

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.