当前位置: 动力学知识库 > 问答 > 编程问答 >

android - How to get file content by Retrofit2, if URL starts to download file

问题描述:

The URL https://itunes.apple.com/search?term=lennon

starts to download file.

HTTP request using HttpURLConnection and InputStream returns the json string.

It is what I need.

But how to get string response using Retrofit2?

I tryed the following code:

public interface ItunesApi {

@GET("/search")

Call<SongsGson> getData(@Query("term=") String search);

}

I send the request here:

 Retrofit retrofit = new Retrofit.Builder()

.baseUrl("https://itunes.apple.com/")

.addConverterFactory(GsonConverterFactory.create())

.build();

ItunesApi itunesApi = retrofit.create(ItunesApi.class);

itunesApi.getData(searchString).enqueue(new Callback<SongsGson>() {

@Override

public void onResponse(Call<SongsGson> call, Response<SongsGson> response) {

int resultCount = response.body().getResultCount();

}

...

}

resultCount is always equal 0.

response.isSuccessful()=true response.message()=OK

The class is below:

public class SongsGson {

@SerializedName("resultCount")

@Expose

private int resultCount;

public SongsGson(){}

public void setResultCount(int resultCount){

this.resultCount = resultCount;

}

public int getResultCount() {

return resultCount;

}

}

Any ideas, please!

分享给朋友:
您可能感兴趣的文章:
随机阅读: