Skip to content

Minimal Example

晓寻遥 edited this page Nov 11, 2021 · 3 revisions

Example

Performing a GET request

public void base_get(){
        String url = "http://localhost:8080/demo/base/add";
        try {
            new Axios(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
}

public void get(){
        String url = "http://localhost:8080/demo/base/add";
        
        try{
            Axios.get(url)
				.then(response ->{
                	System.out.println(response.getStatus());
                	System.out.println(response.getStatusText());
                	System.out.println(response.getHeaders());
                	System.out.println(response.getData());
            	});
        }catch(Exception e){
            e.printStackTrace();
        }
        
        System.out.println("/////////////////////////");

        try {
            Axios.get(
                url,
                new Request().add("value", "11111")
            ).then(response ->{
                System.out.println(response.getStatus());
                System.out.println(response.getStatusText());
                System.out.println(response.getHeaders());
                System.out.println(response.getData());
            });    
        } catch (Exception e) {
            //TODO: handle exception
        }
        
        System.out.println("/////////////////////////");

        try {
            Axios.get(
                url,
                new Request().add("value", "22222"),
                new Header().add("token", "22222")
            ).then(response ->{
                System.out.println(response.getStatus());
                System.out.println(response.getStatusText());
                System.out.println(response.getHeaders());
                System.out.println(response.getData());
            });    
        } catch (Exception e) {
            //TODO: handle exception
        }
}

Clone this wiki locally