retrofit.RetrofitError: 404 Not Found

好久不见. 提交于 2019-12-11 03:34:35

问题


I am working on an android application that utilizes Retrofit to make api calls. When I call the following code:

String searchText = query;
RestAdapter restAdapter = new RestAdapter.Builder()
        .setEndpoint("https://mashape-community-urban-dictionary.p.mashape.com")
        .build();
WordsApiService wordsApi = restAdapter.create(WordsApiService.class);
wordsApi.getWordDefinition(query, new Callback<WordsResponse>() {
    @Override
    public void success(WordsResponse wordsResponse, Response response) {
        System.out.println(response.toString());
    }

    @Override
    public void failure(RetrofitError error) {
        System.out.println(error.getResponse().getStatus());
    }
});

With the following service:

public interface WordsApiService {

    @Headers({
            "X-Mashape-Key : *insert real api key*",
            "Accept: text/plain"
    })
    @GET("/define/")
    void getWordDefinition(@Query("word") String word, Callback<WordsResponse> callback);

}

I am getting a 404 error (retrofit.RetrofitError: 404 Not Found).
When I go into mashape, I see that the service call is going through and hitting the api.

Am I missing something obvious in terms of the configuration of the application?


回答1:


Remove the forward slash from the "define" endpoint path.
Also, the query param is "term" and not "word"

public interface WordsApiService {
    @Headers({
        "X-Mashape-Key : *insert real api key*",
        "Accept: text/plain"
    })
    @GET("/define")
    void getWordDefinition(@Query("term") String term, Callback<WordsResponse> callback);
}


来源:https://stackoverflow.com/questions/29761257/retrofit-retrofiterror-404-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!