How to call a RESTful web service from Android?

后端 未结 9 1768
生来不讨喜
生来不讨喜 2020-11-27 10:58

I have written a REST web service in Netbean IDE using Jersey Framework and Java.

For every request the user needs to provide a username and a password, I know that

9条回答
  •  被撕碎了的回忆
    2020-11-27 11:48

    Using Spring for Android with RestTemplate https://spring.io/guides/gs/consuming-rest-android/

    // The connection URL 
    String url = "https://ajax.googleapis.com/ajax/" + 
        "services/search/web?v=1.0&q={query}";
    
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate();
    
    // Add the String message converter
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
    
    // Make the HTTP GET request, marshaling the response to a String
    String result = restTemplate.getForObject(url, String.class, "Android");
    

提交回复
热议问题