android http 1.1,HTTP/1.1 302 Moved Temporarily - Happens on Android API 16-17

Long story short. I want to download some google sheet files from the internet when my App starts. Here's the situation:

Newer Devices: Everything works 100%, no problems, all files downloaded.

Older Devices (API 16-17): Downloads first sheet file correctly. Fails to download the second file. I get a HTTP/1.1 302 Moved Temporarily problem and file fails to download itself correctly.

I call AsynchTask for both files. AsynchTask runs perfectly and I tried other methods to see if AsynchTask was the problem. In addition, all links are perfectly fine and working.

Here is a part of my AsynchTask class code:

Method that downloads the file:

private String downloadUrl(String urlString) throws IOException {

InputStream is = null;

try {

URL url = new URL(urlString);

HttpsURLConnection conn = (HttpsURLConnection) url.openConnection();

conn.setInstanceFollowRedirects(true); //you still need to handle redirect manully.

HttpsURLConnection.setFollowRedirects(true);

conn.setReadTimeout(10000 /* milliseconds */);

conn.setConnectTimeout(15000 /* milliseconds */);

conn.setInstanceFollowRedirects(true);

conn.setRequestMethod("GET");

conn.setDoInput(true);

// Starts the query

conn.connect();

int responseCode = conn.getResponseCode();

is = conn.getInputStream();

String contentAsString = convertStreamToString(is);

Log.d("contentAsString",contentAsString);

return contentAsString;

} finally {

if (is != null) {

is.close();

}

}

}

String result (HTTP/1.1 302 Moved Temporarily message)

HTTP/1.1 302 Moved Temporarily

Content-Type: text/html; charset=UTF-8

Cache-Control: no-cache, no-store, max-age=0, must-revalidate

Pragma: no-cache

Expires: Mon, 01 Jan 1990 00:00:00 GMT

Date: Tue, 18 Oct 2016 09:26:14 GMT

Location: https://docs.google.com/spreadsheets/d/1hRiDvdLPkQEdTSVxmWEoWXjmCFQodNjMNYi3Fd7yYn0/gviz/tq

P3P: CP="This is not a P3P policy! See https://support.google.com/accounts/answer/151657?hl=en for more info."

P3P: CP="This is not a P3P policy! See https://support.google.com/accounts/answer/151657?hl=en for more info."

Content-Encoding: gzip

X-Content-Type-Options: nosniff

X-XSS-Protection: 1; mode=block

Server: GSE

Set-Cookie: NID=89=afVN4Sa74ZsYuffxNSiXn2wWTJkSUULbtZperbpr8T9hPzHoFzx-uGu_lJUVCkYSd1eZUPUFucffCDHc7lPConnfPpTMbqAOgIcIQoJG6TQFUHzBUNW6bFqUy__ZthsR;Domain=.google.com;Path=/;Expires=Wed, 19-Apr-2017 09:26:14 GMT;HttpOnly

Set-Cookie: NID=89=k5r33ZLA4l__4v1CE1iGrtQbtqoJxOyVxwrSMbsKWviK74u-vM32WdKtt-txFEOhPWo1g9f1CWMXcu6Fuczo4ZCck47D23tIZZRcqpRxkSB0z5w2xI9oj1Jcq8duISiU;Domain=.google.com;Path=/;Expires=Wed, 19-Apr-2017 09:26:14 GMT;HttpOnly

Alt-Svc: quic=":443"; ma=2592000; v="36,35,34,33,32"

Transfer-Encoding: chunked

00000001

00000001

00000001

00000001

��

00000001

��

00000001

��

00000001

��

00000001

��

00000001

��

00000001

��

00000001

m

00dc

��N�0D��

�ܳ�8 !7R�8)ih�hs��U�R�!6��q

G����HoY!�2�X����,J�TfFI��L�4��~����Z�~��eݬ�]D����E��.�k�n$i��/���r,%E��U΍��gl�ӟ1>

v���V!:���Y�/�;.��ۗ�s�?��&��=U�v���õ�,���op4Q8!�4�=�

%��O����ڛ�����

0

After reading a bit about HTTP 302 I know I have to redirect somehow. Problem is I have no idea how to do this. Also, I have no idea why this problem only appears on older android versions.

I've struggling for a week now. Any feedback appreciated! Thank you!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值