http://i.y.qq.com/s.music/fcgi-bin/search_for_qq_cp?g_tk=938407465&uin=0&format=jsonp&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=h5&needNewCode=1&w=%E5%91%A8%E6%9D%B0%E4%BC%A6&zhidaqu=1&catZhida=1&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=1&remoteplace=txt.mqq.all&_=1459991037831&jsonpCallback=jsonp4这个api我一直访问不到,不知道是这个api本身不能被Android访问到呢,还是我写得有问题?求教。
@GET("http://i.y.qq.com/s.music/fcgi-bin/search_for_qq_cp")
Observable<ResponseBody> getMainList(
@Query("g_tk") String g_tk, @Query("uin") String uin, @Query("format") String format, @Query("inCHarset") String inCHarset, @Query("outCharset") String outCharset,
@Query("notice") String notice, @Query("platform") String platform, @Query("needNewCode") String needNewCode, @Query("w") String w,
@Query("zhidaqu") String zhidaqu, @Query("catZhida") String catZhida, @Query("t") String t, @Query("flag") String flag,
@Query("ie") String ie, @Query("sem") String sem, @Query("appr") String appr, @Query("perpage") String perpage,
@Query("n") String n, @Query("p") String p, @Query("remoteplace") String remoteplace, @Query("_") String _,
@Query("jsonCallback") String jsonCallback);
private <T> T configReforit(Class<T> service, String url) {
retrofit = new Retrofit.Builder()
.baseUrl(url)
.client(configClient())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit.create(service);
}
public OkHttpClient configClient() {
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
//为所有请求添加头部 Header 配置的拦截器
Interceptor headerIntercept = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException { Request.Builder builder = chain.request().newBuilder();
Request request = builder
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate")
.addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
.addHeader("Cache-Control", "no-cache")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "RK=RZw4SVlgHd; ptcz=7754687f60603c92040a1409de1f879b17ef63824c632740d194dcb40a33bfc5; pgv_pvi=3170554880; pgv_pvid=705162820; ts_uid=8818401641; eas_sid=Y1N5F3z652W8h5m8g467B3a8n8; LW_uid=r1x5i3r6V298W5E8Y458n0y0R0; pac_uid=1_409023706; tvfe_boss_uuid=676d095a4481997c; _ga=GA1.2.902557457.1542336313; ts_refer=xui.ptlogin2.qq.com/cgi-bin/xlogin; LW_sid=s1J5R4S7m6K8q7R8W0C486n3j0; luin=o0409023706; lskey=00010000a807d972761c2cce1d1d2c98dba32a697f867b644e427c56b2fee71ea1422d8fa30a48e7773810e1; o_cookie=409023706; pgv_info=ssid=s9502803040; uin=o0409023706; ptisp=ctc; qqmusic_uin=; qqmusic_key=; qqmusic_fromtag=; skey=@py2pb0vna; yqq_stat=0; pgv_si=s8344146944")
.addHeader("Host", "i.y.qq.com")
.addHeader("Origin", "http://y.qq.com/")
.addHeader("Pragma", "no-cache")
.addHeader("Referer", "http://y.qq.com/")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")
.build(); return chain.proceed(request); }
}; // Log信息拦截器
if (BuildConfig.DEBUG) {
Interceptor loggingIntercept = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
ResponseBody responseBody = response.body();
BufferedSource source = responseBody.source();
// Buffer the entire body.
source.request(Long.MAX_VALUE);
Buffer buffer = source.buffer();
Charset UTF8 = Charset.forName("UTF-8");
Log.d("REQUEST_JSON", buffer.clone().readString(UTF8));
String logJson = buffer.clone().readString(UTF8);
if (logJson.length() > 4000) {
for (int i = 0; i < logJson.length(); i += 4000) {
if (i + 4000 < logJson.length()) {
Log.d("REQUEST_JSON", logJson.substring(i, i + 4000));
} else {
Log.d("REQUEST_JSON", logJson.substring(i, logJson.length()));
}
}
} Log.d("REQUEST_URL", request.toString());
return response;
}
};
okHttpClient.addInterceptor(loggingIntercept);
} okHttpClient.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
okHttpClient.addNetworkInterceptor(headerIntercept);
return okHttpClient.build();
}
@GET("http://i.y.qq.com/s.music/fcgi-bin/search_for_qq_cp")
Observable<ResponseBody> getMainList(
@Query("g_tk") String g_tk, @Query("uin") String uin, @Query("format") String format, @Query("inCHarset") String inCHarset, @Query("outCharset") String outCharset,
@Query("notice") String notice, @Query("platform") String platform, @Query("needNewCode") String needNewCode, @Query("w") String w,
@Query("zhidaqu") String zhidaqu, @Query("catZhida") String catZhida, @Query("t") String t, @Query("flag") String flag,
@Query("ie") String ie, @Query("sem") String sem, @Query("appr") String appr, @Query("perpage") String perpage,
@Query("n") String n, @Query("p") String p, @Query("remoteplace") String remoteplace, @Query("_") String _,
@Query("jsonCallback") String jsonCallback);
private <T> T configReforit(Class<T> service, String url) {
retrofit = new Retrofit.Builder()
.baseUrl(url)
.client(configClient())
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();
return retrofit.create(service);
}
public OkHttpClient configClient() {
OkHttpClient.Builder okHttpClient = new OkHttpClient.Builder();
//为所有请求添加头部 Header 配置的拦截器
Interceptor headerIntercept = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException { Request.Builder builder = chain.request().newBuilder();
Request request = builder
.addHeader("Accept", "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8")
.addHeader("Accept-Encoding", "gzip, deflate")
.addHeader("Accept-Language", "zh-CN,zh;q=0.9,en;q=0.8")
.addHeader("Cache-Control", "no-cache")
.addHeader("Connection", "keep-alive")
.addHeader("Cookie", "RK=RZw4SVlgHd; ptcz=7754687f60603c92040a1409de1f879b17ef63824c632740d194dcb40a33bfc5; pgv_pvi=3170554880; pgv_pvid=705162820; ts_uid=8818401641; eas_sid=Y1N5F3z652W8h5m8g467B3a8n8; LW_uid=r1x5i3r6V298W5E8Y458n0y0R0; pac_uid=1_409023706; tvfe_boss_uuid=676d095a4481997c; _ga=GA1.2.902557457.1542336313; ts_refer=xui.ptlogin2.qq.com/cgi-bin/xlogin; LW_sid=s1J5R4S7m6K8q7R8W0C486n3j0; luin=o0409023706; lskey=00010000a807d972761c2cce1d1d2c98dba32a697f867b644e427c56b2fee71ea1422d8fa30a48e7773810e1; o_cookie=409023706; pgv_info=ssid=s9502803040; uin=o0409023706; ptisp=ctc; qqmusic_uin=; qqmusic_key=; qqmusic_fromtag=; skey=@py2pb0vna; yqq_stat=0; pgv_si=s8344146944")
.addHeader("Host", "i.y.qq.com")
.addHeader("Origin", "http://y.qq.com/")
.addHeader("Pragma", "no-cache")
.addHeader("Referer", "http://y.qq.com/")
.addHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36")
.build(); return chain.proceed(request); }
}; // Log信息拦截器
if (BuildConfig.DEBUG) {
Interceptor loggingIntercept = new Interceptor() {
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
Response response = chain.proceed(request);
ResponseBody responseBody = response.body();
BufferedSource source = responseBody.source();
// Buffer the entire body.
source.request(Long.MAX_VALUE);
Buffer buffer = source.buffer();
Charset UTF8 = Charset.forName("UTF-8");
Log.d("REQUEST_JSON", buffer.clone().readString(UTF8));
String logJson = buffer.clone().readString(UTF8);
if (logJson.length() > 4000) {
for (int i = 0; i < logJson.length(); i += 4000) {
if (i + 4000 < logJson.length()) {
Log.d("REQUEST_JSON", logJson.substring(i, i + 4000));
} else {
Log.d("REQUEST_JSON", logJson.substring(i, logJson.length()));
}
}
} Log.d("REQUEST_URL", request.toString());
return response;
}
};
okHttpClient.addInterceptor(loggingIntercept);
} okHttpClient.connectTimeout(DEFAULT_TIMEOUT, TimeUnit.SECONDS);
okHttpClient.addNetworkInterceptor(headerIntercept);
return okHttpClient.build();
}
抓包我试了,WireShark没有抓到
所以我在想是不是配置什么的错了。
addHeader("User-Agent", "")
你的参数里有一串 : %E5%91%A8%E6%9D%B0%E4%BC%A6 , 我之前遇到过 出现 中文 , 浏览器中可以解析出这个编码, 在手机中 请求 没有返回值 试着用英文请求 , 或者 研究下 url 编码相关问题
http://i.y.qq.com/s.music/fcgi-bin/search_for_qq_cp?g_tk=938407465&uin=0&format=jsonp&inCharset=utf-8&outCharset=utf-8¬ice=0&platform=h5&needNewCode=1&w=%E5%91%A8%E6%9D%B0%E4%BC%A6&zhidaqu=1&catZhida=1&t=0&flag=1&ie=utf-8&sem=1&aggr=0&perpage=20&n=20&p=1&remoteplace=txt.mqq.all&_=1459991037831&jsonpCallback=jsonp4
https://baike.baidu.com/item/URL%E7%BC%96%E7%A0%81/3703727?fr=aladdin
https://www.cnblogs.com/jerrysion/p/5522673.html
https://www.baidu.com/s?wd=url%20%E7%BC%96%E7%A0%81&rsv_spt=1&rsv_iqid=0xd3c109090006446c&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=baiduhome_pg&rsv_enter=1&rsv_sug3=11&rsv_sug1=6&rsv_sug7=101&rsv_t=d5c9zYKoMK0lVo1WOCT0ZyBDUANpvrQt4d2eKhz2dFHEhNDVij%2BgWDWqwD3aOAFShbzu工具 :
http://tool.chinaz.com/Tools/urlencode.aspx