【发布时间】:2018-11-13 21:21:37
【问题描述】:
我正在尝试使用改造从服务器下载文件。使用 HttpLoggingInterceptor 我尝试记录正在发生的事情。我可以找到文件名。但是响应正文是空的。
我不熟悉使用改造。有人可以指出我哪里出错了
改造客户端界面:
public interface DownloadTransactions {
@Streaming
@GET("common/frontend/member/download.aspx")
Call<Void> getBalancesAndTransactions(@Header("Cookie") String header);
}
Java 调用:
void downloadData() {
OkHttpClient.Builder client = new OkHttpClient.Builder();
client.connectTimeout(15, TimeUnit.SECONDS)
.readTimeout(15, TimeUnit.SECONDS);
if (BuildConfig.DEBUG) {
HttpLoggingInterceptor logging = new HttpLoggingInterceptor();
logging.setLevel(HttpLoggingInterceptor.Level.BODY);
client.addInterceptor(logging);
}
Retrofit.Builder builder = new Retrofit.Builder();
Retrofit retrofit = builder.client(client.build())
.baseUrl("https://" + getString(R.string.root_url))
.addConverterFactory(ScalarsConverterFactory.create())
.build();
DownloadTransactions downloadTransactions = retrofit.create(DownloadTransactions.class);
Call<Void> call = downloadTransactions.getBalancesAndTransactions(CommsManager.getInstance().getASPSessionId());
call.enqueue(new Callback<Void>() {
@Override
public void onResponse(Call<Void> call, retrofit2.Response<Void> response) {
Log.v(TAG, "success transactions: --------" + response);
}
@Override
public void onFailure(Call<Void> call, Throwable t) {
Log.v(TAG, "failure transactions: --------");
}
});
}
日志中的响应:
<-- 200 OK https://xxxxx.com/common/xxx/member/download.aspx (387ms)
D/OkHttp: Cache-Control: private
D/OkHttp: Content-Type: text/csv; charset=utf-16
D/OkHttp: Server: Microsoft-IIS/8.5
D/OkHttp: Content-Disposition: attachment; filename=Account_Summary_8978_04062018_142921.csv
D/OkHttp: X-AspNet-Version: 4.0.30319
D/OkHttp: X-Powered-By: ASP.NET
D/OkHttp: Date: Mon, 04 Jun 2018 13:29:21 GMT
D/OkHttp: Connection: keep-alive
D/OkHttp: Content-Length: 446900
D/OkHttp: Set-Cookie: xxx; path=/; Httponly; Secure
D/OkHttp: <-- END HTTP (binary 446900-byte body omitted)
D/Accounts Overview: success transactions: --------
Response{protocol=http/1.1, code=200, message=OK, url=xxx}
【问题讨论】: