The code is as follows:
import java.io.BufferedReader;import java.io.DataOutputStream;import java.io.IOException;import java.io.InputStreamReader;import java.net.HttpURLConnection;import java.net.URL;import net.sf.json.JSONObject;public class InterfaceRequest {//Simulate sending interface to Tencent Cloud//Interface private final static String URL = "https://console.tim.qq.com/v4/im_open_login_svc/account_import?";/** * @param args * @throws IOException */public static void main(String[] args) throws IOException {// TODO Auto-generated method stub//Connect server HttpURLConnection connection = connection(URL);DataOutputStream out = new DataOutputStream(connection.getOutputStream());JSONObject obj = new JSONObject(); obj.element("Identifier", "hehe");System.out.println(obj.toString());//Send in json data encoded in UTF-8 format to Tencent out.write(obj.toString().getBytes("UTF-8"));out.flush();out.close();//Get the result returned by the server BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));String lines;StringBuffer sb = new StringBuffer(""); while ((lines = reader.readLine()) != null) {lines = new String(lines.getBytes(), "utf-8");sb.append(lines);}reader.close();}public static HttpURLConnection connection(String URL) throws IOException {URL url = new URL(URL);HttpURLConnection connection = (HttpURLConnection) url.openConnection();connection.setDoOutput(true);connection.setDoInput(true);connection.setRequestMethod("POST");connection.setUseCaches(false);connection.setInstanceFollowRedirects(true);connection.setRequestProperty("Content-Type","application/x-www-form-urlencoded;charset=UTF-8");connection.connect();return connection;// TODO Auto-generated method stub}}The above example of Java sending requests to the backend server interface in json format is all the content I share with you. I hope you can give you a reference and I hope you can support Wulin.com more.