android


JSON url Redirection fails


I've JSON parsing Asynchronous task, When I use URL http://example.com/json/note.json it is working (Using free JSON hosting service, I can't edit after saving). But my file is not placed permanently on one link. So I've Redirecting new JSON URL using URL redirection service. When I use my URL redirection service, my URL doesn't redirects to http://example.com/json/new_note.json.
new JSONAsyncTask().execute("http://example.com/json/note.json"); //works
new JSONAsyncTask().execute("http://example.com/redirection_service_url"); //doesn't works
JSONAsyncTask
class JSONAsyncTask extends AsyncTask<String, Void, Boolean> {
#Override
protected void onPreExecute() {
super.onPreExecute();
}
#Override
protected Boolean doInBackground(String... urls) {
arraylist = new ArrayList<HashMap<String, String>>();
try {
//------------------>>
HttpGet httppost = new HttpGet(urls[0]);
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(httppost);
StatusLine stat = response.getStatusLine();
int status = response.getStatusLine().getStatusCode();
if (status == 200) {
HttpEntity entity = response.getEntity();
String data = EntityUtils.toString(entity);
JSONObject jsono = new JSONObject(data);
JSONArray jarray = jsono.getJSONArray("array");
for (int i = 0; i < jarray.length(); i++) {
HashMap<String, String> map = new HashMap<String, String>();
jsono = jarray.getJSONObject(i);
// Retrive JSON Objects
// Set the JSON Objects into the array
arraylist.add(map);
}
return true;
} else {
Log.e("Error", "Something went wrong");
}
//------------------>>
} catch (ParseException e1) {
e1.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return false;
}
protected void onPostExecute(Boolean result) {
if (result == false) {
Toast.makeText(getApplicationContext(), "Unable to Fetch data from server", Toast.LENGTH_LONG).show();
}
}
}
Using my URL redirection service URL in browsers shows my JSON data, I ensured it has no errors.
Please help!
In my experience, Android doesn't support redirecting on HTTP connections even when the method is GET.
You should take your HTTP response and extract the Location header and then make another request for the JSON payload.

Related Links

How to update column only is its empty in sqlite?
How to implement viewpager in recyclerview
Android how to send message/object to an activity from an activity that was opened from a notification
Rendering Problems: attrs.xml is not found
Using Picasso with ImageView
Which Context to call startService
How to Check that FragmentTransaction.replace() Updates Fragment
Cookie not sent with the websocket request
How to open Menu Context Android with click button?
Mock location does not work in Android Studio Emulator
How to add new item to gridview in first position?
Android Views Creation Callback
Where to get Theme.AppCompat.Light.NoActionBar document and how to modify styles globally for android?
Android App development using xamarin
horizontal scroll of Iframe on mobile
is there any plugin/library by which i can import blender animations?

Categories

HOME
windows
asp.net-web-api
httparty
polymer
powerpoint
flex
zend-framework
pclxl
static-site
nfs
special-characters
discrete-mathematics
rcloud
drop-down-menu
redis-sentinel
supervisor
symmetricds
jmp
gmm
sencha-touch
charles
articulate-storyline
object-storage
8051
paperjs
boost-asio
event-flow
scatter3d
card.io
dynamic-jasper
modernizr
flatmap
apns-php
verifiable-c
diacritics
setup.py
stringtokenizer
dcmtk
print-css
avcapturedevice
show-hide
uiimage
jquery-ui-draggable
spring-integration-sftp
globalize
vugen
identification
activeperl
datamaps
convex-optimization
google-cse
payara-micro
pair-programming
stdmap
java-bytecode-asm
modelsim
edit
headless
dt
janus
monkey
bootstrap-tags-input
android-instrumentation
javafx-css
change-tracking
taocp
atlas
dotnetnuke-7
file-uri
greatest-n-per-group
android-wake-lock
php-socket
redis-cluster
ikiwiki
cortex-m
oracle-spatial
xvim
linked-tables
entity-framework-4.3
dot.js
code-documentation
boost-program-options
jbake
crowd
rickshaw
paw
strawberry-perl
trdion2011
reflector
fpdi
multitasking
android-usb
light
ebay-lms
process-explorer
font-awesome-4.0.0
android-icons
argouml
idn
intersect
redis-py
monotouch.dialog
apache-whirr
jsr286
infobright
xcelsius
google-ajax-api
unattended-processing
object-database

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App