android


basicnetwork.performrequest exception on fetching data from a GET API android


I need to fetch data in android from the in the data array of the following api
http://www.quandl.com/api/v3/datasets/MULTPL/SP500_REAL_PRICE_MONTH.json?start_date=1915-01-01&api_key=UPqWzYxopvhzdoRt5jTS
I tried both JSONObject request and string request
JsonObjectRequest obreq = new JsonObjectRequest(Request.Method.GET, Url.URL_SNP_2,
// The third parameter Listener overrides the method onResponse() and passes
//JSONObject as a parameter
new Response.Listener<JSONObject>() {
// Takes the response from the JSON request
#Override
public void onResponse(JSONObject response) {
Log.d("Response", "Getting CAB Response: " + response.toString());
Toast.makeText(Fragment_CAB_SNP_2.this.getActivity(), "response:" + response.toString(), Toast.LENGTH_LONG).show();
}
// Try and catch are included to handle any errors due to JSON
},
// The final parameter overrides the method onErrorResponse() and passes VolleyError
//as a parameter
new Response.ErrorListener() {
#Override
// Handles errors that occur due to Volley
public void onErrorResponse(VolleyError error) {
Log.e("Volley", "Error");
}
}
);
// Adds the JSON object request "obreq" to the request queue
requestQueue.add(obreq);
but it gives following exception
E/Volley: [35011] BasicNetwork.performRequest: Request at http://www.quandl.com/api/v3/datasets/MULTPL/SP500_REAL_PRICE_MONTH.json?start_date=1915-01-01&api_key=UPqWzYxopvhzdoRt5jTS has been redirected to https://www.quandl.com/api/v3/datasets/MULTPL/SP500_REAL_PRICE_MONTH.json?start_date=1915-01-01&api_key=UPqWzYxopvhzdoRt5jTS
05-11 23:02:25.134 27238-27238/com. E/Volley: Error
no response is fetched.pls help me
First check for the response data in the VolleyError and parse it your self.
see what error it is throwing.
Volley throws a ServerError exception that contains the raw network response.
So you can do something similar to this in your error listener:
/* import com.android.volley.toolbox.HttpHeaderParser; */
public void onErrorResponse(VolleyError error) {
// As of f605da3 the following should work
NetworkResponse response = error.networkResponse;
if (error instanceof ServerError && response != null) {
try {
String res = new String(response.data,
HttpHeaderParser.parseCharset(response.headers, "utf-8"));
// Now you can use any deserializer to make sense of data
JSONObject obj = new JSONObject(res);
} catch (UnsupportedEncodingException e1) {
// Couldn't properly decode data to string
e1.printStackTrace();
} catch (JSONException e2) {
// returned data is not JSONObject?
e2.printStackTrace();
}
}
}

Related Links

Unity3D - My games working fine on Editor, acting strange on mobile device and emulator
How can I view my Android application Database ? [Android] [duplicate]
Android how get Context from specific class being in Service
When Activity is destroyed, all services execute onStart() methods, including activity that is destroyed
Strings.xml equivalent in HTML
How to obtain the value for a reference attribute
Combining two asynk task in one activity sharing same adapter for both viewpager
When an app with in-app purchase is removed by Google from the Play store, what happens to users in regard to the apk?
create several OkHttp3 clients with same connection pool
Filtering custom adapter on more than one condition
Weird Android intent-filter pathPattern issue while deep linking
Android NDK stand alone compilation getting error
Detach a view from layout and make it full-screen?
How to built C code with OpenCV and NDK for Android?
Can I instruct my network requests to only use WiFi, even when both WiFi and Data networks are available?
Image getting destroyed when being put in drawables folder

Categories

HOME
porting
jpa
polymer
android-studio-2.2
twig
static
apache-spark-mllib
jelastic
graphics
shiro
entity-framework-core
parameters
discrete-mathematics
extjs4.2
project
vimdiff
plist
why3
jsonpath
google-form
flatpak
parameter-passing
coin3d
event-sourcing
atlassian-stash
oledb
breadth-first-search
r-mice
pimcore
scriptella
pic32
jquery-multiselect
licensing
corpus
8051
exchangewebservices
cppreference
recurring-events
kodi
dumpbin
git-squash
rselenium
dsx-desktop
nested-lists
openerp-7
docfx
reactivekit
node-mssql
diacritics
p4merge
magento-1.9.3
laravel-elixir
logback-groovy
android-exoplayer
wc
show-hide
apache-spark-dataset
spring-integration-sftp
insight
carrot2
java-bytecode-asm
subnet
quicktime
shinobi
choice
pytables
builtins
myspace
signalr.client
ng-grid
delta
lean
respondcms
spreadjs
findfirst
poppler
.bash-profile
rpart
batik
eoferror
ocra
j-security-check
procedural-programming
infosphere-spl
nodelist
execve
boost-program-options
administration
sql-scripts
webfinger
psr-4
jama
buffering
radiant
qscrollarea
getopt
inappsettingskit
cffile
cmmi
nebula
flex++
wp7test
mantle
fragmenttransaction
zope.interface
fusefabric
apache-whirr
landscape-portrait
uideviceorientation
ie-compatibility-mode
addchild
blender-2.49
complex-event-processing
fail-fast-fail-early
linfu-dynamicproxy
business-model
information-management
lemmatization
wspbuilder

Resources

Encrypt Message