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)