java - Httpget from webpage doesn't return content when run on Android -
i trying contents of page: http://www.washingtonpost.com/wp-srv/simulation/simulation_test.json
i able contents in java project. here code:
httpclient client = new defaulthttpclient(); httpget request = new httpget(url); httpresponse response = client.execute(request); bufferedreader rd = new bufferedreader( new inputstreamreader(response.getentity().getcontent())); stringbuffer result = new stringbuffer(); string line = ""; while ((line = rd.readline()) != null) { result.append(line); }
this prints contents in java project.
however, when execute code in android project, following in return :
<html><head><title>cisco systems inc. web authentication redirect</title><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="pragma" content="no-cache"><meta http-equiv="expires" content="-1"><meta http-equiv="refresh" content="1; url=https://1.1.1.1/login.html?redirect=www.washingtonpost.com/wp-srv/simulation/simulation_test.json"></head></html>
how can solve problem? why occur in android project , not in java project?
thanks
ref android client
assume not useing proxy when on android connected wifi.
assume on android not using net interface 3g/4g
assume using android httpclient packages , not apache httpclient.
assume manifest has granted web permissions.
you have know above in order debug.
you bunch of default headers default packages when invoke these:
httpclient client = new defaulthttpclient(); httpget request = new httpget(url);
you need either turn on logging wire & headers or need dump headers request know whats in there.
then , compare android generated http ( headers ) curl test script see below.. if android headers reasonably close ( dont need exact there can extras in there 'gzip' encoding ) curl headers , android work. curl example shows 3 headers , make wild guess android client , default, setting 7 or 8 headers , wp server not in cruft of headers , redirecting logon.
@ ~$ curl --verbose http://www.washingtonpost.com/wp-srv/simulation/simulation_test.json * connect() www.washingtonpost.com port 80 (#0) * trying 23.204.109.48... * connected * connected www.washingtonpost.com (23.204.109.48) port 80 (#0) > /wp-srv/simulation/simulation_test.json http/1.1 > user-agent: curl/7.28.1-dev > host: www.washingtonpost.com > accept: */* > < http/1.1 200 ok < server: webserver < content-type: text/plain < last-modified: wed, 12 feb 2014 21:16:22 gmt < content-length: 58187 < etag: "e34b-52fbe4a6" < accept-ranges: bytes < date: mon, 10 mar 2014 16:54:42 gmt < connection: keep-alive < { "posts": [
android httpclient 4.3 sample header logs turned on...
d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> put /1/classes/mediaitem/xpdlazbuzv http/1.1 d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> content-length: 90 d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> content-type: application/json; charset=utf-8 d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> host: api.parse.com d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> connection: keep-alive d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> user-agent: apache-httpclient/unavailable (java 1.5) d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> accept-encoding: gzip,deflate d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> x-parse-session-token: li9ds d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> x-parse-application-id: 3qovv d/ch.boye.httpclientandroidlib.headers(15360): http-outgoing-2 >> x-parse-rest-api-key: theoj d/
Comments
Post a Comment