改造中的呼叫入队功能

时间:2018-11-12 13:26:29

标签: android retrofit2

这是我第一次使用Retrofit2,并且反复得到response.isSuccessful()== FALSE 这是我的代码:

Tools > Extensions and Updates... > Online Visual Studio Gallery > Find Nuget Package 2.12 and instal it again

可以有人帮我解决这个问题吗 谢谢^ _ ^

2 个答案:

答案 0 :(得分:0)

这是APIservice接口

public interface APIService {

    @GET("node/read.php")
    Call <NodeList> getNodes();

    @GET("data/read.php")
    //@FormUrlEncoded
    Call<DataList> getDatas();

    @POST("data/readByNode.php")
    @FormUrlEncoded
    Call<DataList> getDatasByNode(
            @Field("node") String nodeName
    );

    //@POST("user/check.php")
    @POST("user/check.php")
    @FormUrlEncoded
    Call<CheckUser> userLogIn(
                        @Field("username") String username,
                        @Field("password") String password
    );
    @POST("prediction/readDayPrediction.php")
    @FormUrlEncoded
    Call<Prediction> sendDifference(
            @Field("difference") Integer difference
    );
}

这是RetrofitClient类:

public class RetrofitClient {

    private static Retrofit retrofit = null;
    static Gson gson = new GsonBuilder().setDateFormat("yyyy-MM-dd HH:mm:ss").setLenient().create();

    public static Retrofit getClient(String baseUrl) {
        if (retrofit==null) {
            retrofit = new Retrofit.Builder()
                    .baseUrl(baseUrl)
                    .addConverterFactory(GsonConverterFactory.create(gson))
                    .build();
        }
        return retrofit;
    }
}

答案 1 :(得分:0)

<pre> try to change baseUrl www.servername.com/ don't append /apiV5 to baseurl but add it @Get("apiV5/user/check.php") fun check() </pre>