RestTemplate client with cookies

后端 未结 7 692
谎友^
谎友^ 2020-12-08 15:08

I\'m writing a simple client in Java to allow reusable use of proprietary virus scanning software accessible through a RESTful API. To upload a file for scanning the API req

相关标签:
7条回答
  • 2020-12-08 15:58
                        package zuulx;
    
                    import java.net.URI;
                    import java.net.URISyntaxException;
    
                    import org.springframework.http.HttpEntity;
                    import org.springframework.http.HttpHeaders;
                    import org.springframework.http.HttpMethod;
                    import org.springframework.http.ResponseEntity;
                    import org.springframework.web.client.RestTemplate;
    
                    public class CookieTest {
                    /**
                     * 
                     * array(1) {
                      ["aaa"]=>
                      string(2) "11"
                    }
    
    
                     * @param args
                     * @throws URISyntaxException
                     */
                        public static void main(String[] args) throws URISyntaxException {
                            
                            HttpHeaders headers = new HttpHeaders();
                              headers.add("Cookie", "aaa=11" );
                              
                            
                               RestTemplate restTemplate = new RestTemplate();
                               
                        //  URI url= new URI("http://localhost:9088/cktest");
                        //  System.out.println( restTemplate.getForObject(url, String.class));  
                            
                              String url = "http://localhost/showck.php";
                              url="http://localhost:9088/cktest";
                            ResponseEntity response = restTemplate.exchange(url,
                                      HttpMethod.GET,
                                      new HttpEntity (headers) ,String.class);
                              
                              System.out.println(response.getBody());
                            
                            
                            //http://localhost/showck.php
    
                        }
    
                    }
    
    0 讨论(0)
提交回复
热议问题