简体   繁体   中英

Wrong Response Body while trying to download photo using Retrofit2

I'm using Retrofit 2.0.0-beta2 and I need to download some files from my PHP server. My first approach which worked was to directly use the GET method from its relative server path and I was getting the correct bytes.

Now I've tried something more secure that delivers the file to me based on some checks. It automatically fetches the file path from the DB and checks if the user session is correct. This works in browser tests, both Chrome PC and Chrome from Android correctly download some photos.

I'm serving the file using the X-Sendfile header like so:

header("X-Sendfile: $file_name");
header("Content-type: image/jpeg");
header('Content-Disposition: attachment; filename="' . basename($file_name) . '"');

The Android-side call looks like this:

@Streaming
@GET("/card/download")
Call<ResponseBody> getCard(@Query("filename") String filename);

All I'm getting when opening the files is the echoed text response from server. Is there any way I can receive the "correct" files?

Apparently there was some sort of problem installing the mod.

I also updated OkHttp to version 2.7.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM