Alf*_*sen 7 java networking android retrofit
我正在使用Square的Retrofit Client从Android应用程序发出简单的请求.像这样:
RestAdapter restAdapter = new RestAdapter.Builder()
.setServer(Configurations.getInstance().plistMap.get("PTBaseURL"))
.setRequestHeaders(new RequestHeaders() {
@Override
public List<Header> get() {
List<Header> headers = new ArrayList<Header>();
Header authHeader = new Header("Authorization", authType + " " + UserManager.getInstance().currentUser.token);
headers.add(authHeader);
}
return headers;
}
})
.build();
this.service = restAdapter.create(ClientInterface.class);
Run Code Online (Sandbox Code Playgroud)
一个端点重定向到不同的URL(s3).由于对此问题不重要的原因,重定向请求失败,因此我的callback.failure(error)方法被调用.我需要能够在某些时候访问和修改重定向URL或请求,最好是在callback.failure().我怎样才能做到这一点?
或者,有没有办法设置类似的东西followRedirects = false(并以这种方式拦截重定向)?
用OkHttp:
public static void setFollowRedirects (boolean auto)
public OkHttpClient setFollowProtocolRedirects(boolean followProtocolRedirects)
Run Code Online (Sandbox Code Playgroud)
用HttpURLConnection:
public static void setFollowRedirects (boolean auto)
public void setInstanceFollowRedirects (boolean followRedirects)
Run Code Online (Sandbox Code Playgroud)
见这里的讨论.
| 归档时间: |
|
| 查看次数: |
6005 次 |
| 最近记录: |