【问题标题】:Get response from server with retrofit通过改造从服务器获取响应
【发布时间】:2015-09-15 09:47:39
【问题描述】:

我想使用 retforit 从服务器获取响应。 这是一些代码:

public class ApiManager {
private static String API_URL = "http://192.168.0.142:8080";
private static ApiService service;

interface ApiService {

    @GET("/login")
    Call<User> auth(Callback<User> cb);
}

private ApiManager() {
    Retrofit retrofit = new Retrofit.Builder()
            .baseUrl(API_URL)
            .addConverterFactory(GsonConverterFactory.create())
            .build();

    service = retrofit.create(ApiService.class);
}

public void login(String login, String password) {
    service.auth(new Callback<User>() {
                     @Override
                     public void onResponse(retrofit.Response<User> response) {

                     }

                     @Override
                     public void onFailure(Throwable t) {

                     }
                 }

    );

和用户类:

公共类用户{
私有字符串令牌;

public String getToken() {
    return token;
}

public void setToken(String token) {
    this.token = token;
}

}

服务器无论如何都会返回 JSONObject {"token": "verysecrettoken"}。

当我调用 login 方法时,应用程序因异常 java.lang.IllegalArgumentException: No Retrofit annotation found. (parameter #1) 而崩溃

怎么了?我在哪里可以找到改造文档? Call 是什么? 请帮忙

【问题讨论】:

    标签: android retrofit


    【解决方案1】:

    调用 enqueue,你有错误的语法。试试这个早期的文档:

    http://inthecheesefactory.com/blog/retrofit-2.0/en

    【讨论】:

    • 好文章!谢谢!
    【解决方案2】:

    这里提出了同样的问题:No Retrofit annotation found. (parameter #1)

    可在此处找到改造文档:http://square.github.io/retrofit/

    【讨论】:

    • 这个关于旧版本改造的问题 :( square.github.io/retrofit 在这个链接上只有一些例子,没有好的文档
    猜你喜欢
    • 1970-01-01
    • 2019-09-28
    • 1970-01-01
    • 2015-06-10
    • 1970-01-01
    • 2021-04-17
    • 2015-11-16
    • 2018-05-26
    • 1970-01-01
    相关资源
    最近更新 更多