WebClient of HTTP protocol interface invocation

Source: Internet
Author: User
the HTTP protocol interface typically has a GET request and a POST request, and here's a summary of the several types of calls you'll use: First: WebClient send get requests
Import Net.sf.json.JSONObject;
Import org.apache.cxf.jaxrs.client.WebClient;
Import Org.junit.Test;
@Test public
void GetResponse () {
    String url = ' http://ip:port/test ';
    1. Establish the connection
    WebClient WC = webclient.create (URL); 
    2. Gets the JSON
    String str = wc.accept ("Application/json") returned by the server. Get (string.class);
    System.out.println (str);
    3. According to the returned data format itself, assemble the data. This assumes that the returned data format is
    //{"status": 4000, "data": [{"Name": "Youyou"},{"name": "Test"}]}, converting JSON to object
    Jsonobject Jsonobject =jsonobject.fromobject (str); 
    System.out.println (Jsonobject.get ("status")); 4000
}
The second type: WebClient send a POST request

Similar to get way, need to call WebClient post method, here temporarily, there is a problem to write. PS: Recently I am forming their own technical exchange group, interested friends can add group.

Group number: 198450184 (Lea project group)

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.