簡體   English   中英

我如何獲取發送到robospice改造的請求字符串URL?

[英]How can I get request string URL that sent to robospice retrofit?

我搜索了但沒有找到有用的信息。 嘗試處理REST API客戶端時,我將robospice與retofit結合使用,我想查看發送到服務的請求字符串。 是否可以從Robospice或Retrofit提取整個字符串URL?

這是我的界面:

public interface GoogleSearchInterface {
public static final String BASE_URL = "https://www.googleapis.com/customsearch";
public static final String API_KEY = "AIzaSyCCuxxVLzm2sZP-adhRNYKeSck1mMMgsAM";
public static final String CUSTOM_SEARCH_ID = "001734592082236324715:sob9rqk49yg";
public static final String SEARCH_TYPE_IMAGE = "image";
static final String FILTER = "&fields=queries(nextPage(startIndex,count),request(startIndex,count)),searchInformation(totalResults),items(title,link,displayLink,mime," +
        "image)";
static final String QUERY = "/v1?key="+API_KEY+
                            "&cx="+CUSTOM_SEARCH_ID+
                            "&searchType="+SEARCH_TYPE_IMAGE+FILTER;

@GET(QUERY)
public GoogleSearchResponse search(@Query("q") String query,
                                   @Query("start") long startIndex);
@GET(QUERY)
public GoogleSearchResponse search(@Query("q") String query,
                                   @Query("start") long startIndex,
                                   @Query("searchType") String searchType,
                                   @Query("limit") String limit,
                                   @Query("offset") String offset);

SpiceRequest

 String query;
long startIndex;
String limit;
String offset;

public SampleRetrofitSpiceRequest(String query,long startIndex,String limit,String offset) {
    super(GoogleSearchResponse.class,GoogleSearchInterface.class);
    this.query = query;
    this.startIndex = startIndex;
    this.limit=limit;
    this.offset=offset;
}

public SampleRetrofitSpiceRequest(String query, long startIndex) {
    super(GoogleSearchResponse.class, GoogleSearchInterface.class);
    this.query = query;
    this.startIndex = startIndex;
}
@Override
public GoogleSearchResponse loadDataFromNetwork() throws Exception {
    return getService().search(query,startIndex);
}

SpiceService

public class SampleRetrofitSpiceService extends RetrofitGsonSpiceService {
@Override
public void onCreate() {
    super.onCreate();
    addRetrofitInterface(GoogleSearchInterface.class);
}

@Override
protected String getServerUrl() {
    return GoogleSearchInterface.BASE_URL;
}

發送請求的方法

 public void sendRequest(String query,int page){
    searchQuery = query;
    request = new SampleRetrofitSpiceRequest(query, page);
   spiceManager.execute(request, query, DurationInMillis.ONE_WEEK, new RequestImageListener());
 /*   try {
        spiceManager.getFromCache(GoogleSearchResponse.class, "country",DurationInMillis.ONE_WEEK,new RequestImageListener());
    }catch(Exception e){
        e.printStackTrace();
    }*/
    request=null;
}

PS我正在編寫一個將進行圖像搜索的應用程序,前10個結果已成功加載,但下一頁正在重復上一頁。 我花了很多時間,在spiceRequst中發送的Google api的&start參數被忽略了。 謝謝。

解決方案是在自定義SpiceService.class中覆蓋此方法

 @Override
protected RestAdapter.Builder createRestAdapterBuilder() {
    RestAdapter.Builder builder = new RestAdapter.Builder()
            .setLogLevel(RestAdapter.LogLevel.BASIC)
            .setConverter(getConverter())
            .setEndpoint(getServerUrl());
    return builder;
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM