How to call a RESTful web service from Android?

后端 未结 9 1749
生来不讨喜
生来不讨喜 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:35

    I used OkHttpClient to call restful web service. It's very simple.

    OkHttpClient httpClient = new OkHttpClient();
    Request request = new Request.Builder()
                    .url(url)
                    .build();
    
    Response response = httpClient.newCall(request).execute();
    String body = response.body().string()
    
    0 讨论(0)
  • 2020-11-27 11:40

    Here is my Library That I have created for simple Webservice Calling,

    You can use this by adding a one line gradle dependency -

    compile 'com.scantity.ScHttpLibrary:ScHttpLibrary:1.0.0'
    

    Here is the demonstration of using.

    https://github.com/vishalchhodwani1992/httpLibrary

    0 讨论(0)
  • 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");
    
    0 讨论(0)
提交回复
热议问题