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 can I two way sync data between android device and webserver?
How to use SharedPreferences to save more than one values?
Android: Workaround for support.v4.app.Fragment -> Fragment classcastexception?
All EditText inside an alert Dialog are not visible
Launch Custom Dialog from Alert Dialog - NullPointer error
Realtime html 5 application polling
Java null pointer exception while using google maps in Android
Reflection for Finding Classes in Android Application
How to improve memory usage with BitmapFactory.decodebyteArray()?
Send touch screen event to foreground activity (only from APK)
How to auto-pair to another Android device over Bluetooth without prompting for a pin?
I want to download an audio from the server
Can we add our application setting menu to the android device settings menu
Simulate Multi Touch in Android Emulator
Clossing expanded child views in ExpandableListActivity
Is this code Correct ? Send Email Via Android

Categories

HOME
beautifulsoup
hyperlink
datastore
ns-3
swt
owl-carousel
appcelerator
javacc
google-cloud-functions
big-o
emscripten
jax-ws
elasticsearch-5
extjs4.2
okhttp
fabric.io
minecraft-forge
vimdiff
endeca
openpyxl
distribution
why3
intercom
qsqlquery
screen-readers
gruntfile
glyphicons
esoteric-languages
video-editing
nim
nodemcu
sar
symbols
question2answer
inno-download-plugin
visual-studio-extensions
pchart
object-storage
game-theory
fable-f#
corpus
delimiter
angular-translate
ceylon
scrollview
dotspatial
powershell-ise
cognos-bi
dynamic-jasper
python-pptx
sql-server-ce
filesystemwatcher
health-monitoring
metawidget
setup.py
watchface
naming
chronicle-map
contract
knime
openal
proget
page-replacement
arq
tinkerpop
boxing
opengl-4
excel-dna
arules
template-toolkit
swingworker
javafx-css
chromium-os
meteor-packages
redbeard-ios
parfor
xcode-server
resourcemanager
installshield-2010
nss
project-organization
dbamp
boost-serialization
nupic
thread-sleep
relativelayout
android-launcher
opserver
liquid-layout
snoop
phpldapadmin
gamekit
public-html
angular-gettext
primitive-types
vbe
drupal-nodes
notorm
modular
rolify
inappsettingskit
cmmi
cardreader
stress
webdev.webserver
cuteeditor
nhprof
metaweblog
easyb
nstokenfield
wordprocessingml
linfu-dynamicproxy
appliance

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