With what can I replace http deprecated methods?

后端 未结 4 927
迷失自我
迷失自我 2021-01-02 15:15

I was following a tutorial and I got to a point where a lot of the code is deprecated.

ArrayList dataToSend = new ArrayList<>();
d         


        
4条回答
  •  时光取名叫无心
    2021-01-02 15:47

    You should try Retrofit, it's more simple to use that library instead of perform http requests. It was made for simplify communication between java and REST API.

    square.github.io/retrofit/

    I give you a sample from the documentation

    public interface GitHubService {
       @GET("/users/{user}/repos")
       List listRepos(@Path("user") String user);
    }
    

    The RestAdapter class generates an implementation of the GitHubService interface.

    RestAdapter restAdapter = new RestAdapter.Builder()
    .setEndpoint("https://api.github.com")
    .build();
    
    GitHubService service = restAdapter.create(GitHubService.class);
    

    Each call on the generated GitHubService makes an HTTP request to the remote webserver.

    List repos = service.listRepos("octocat");
    

提交回复
热议问题