http - FileNotFoundException in Android with HttpURLConnection -


i'm getting following error whenever try run unit tests in android - tests pass when run outside of android:

07-18 15:43:44.816: w/system.err(545): uk.co.redfruit.libraries.srpdb.exceptions.srbclientexception: java.io.filenotfoundexce$ 07-18 15:43:44.816: w/system.err(545):  @ uk.co.redfruit.libraries.srpdb.srpdbclient.getcontent(srpdbclient.java:116) 07-18 15:43:44.816: w/system.err(545):  @ uk.co.monkeypower.android.straightrazordatabase.test.srpdbclienttest.testgetconten$ 07-18 15:43:44.826: w/system.err(545):  @ java.lang.reflect.method.invokenative(native method) 07-18 15:43:44.826: w/system.err(545):  @ java.lang.reflect.method.invoke(method.java:507) 07-18 15:43:44.826: w/system.err(545):  @ junit.framework.testcase.runtest(testcase.java:154) 07-18 15:43:44.826: w/system.err(545):  @ junit.framework.testcase.runbare(testcase.java:127) 07-18 15:43:44.826: w/system.err(545):  @ junit.framework.testresult$1.protect(testresult.java:106) 07-18 15:43:44.826: w/system.err(545):  @ junit.framework.testresult.runprotected(testresult.java:124) 07-18 15:43:44.826: w/system.err(545):  @ junit.framework.testresult.run(testresult.java:109) 07-18 15:43:44.826: w/system.err(545):  @ junit.framework.testcase.run(testcase.java:118) 07-18 15:43:44.826: w/system.err(545):  @ android.test.androidtestrunner.runtest(androidtestrunner.java:169) 07-18 15:43:44.826: w/system.err(545):  @ android.test.androidtestrunner.runtest(androidtestrunner.java:154) 07-18 15:43:44.826: w/system.err(545):  @ android.test.instrumentationtestrunner.onstart(instrumentationtestrunner.java:529) 07-18 15:43:44.836: w/system.err(545):  @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1448) 07-18 15:43:44.836: w/system.err(545): caused by: java.io.filenotfoundexception: http://straightrazorplace.com/srpwiki/index.$ 07-18 15:43:44.836: w/system.err(545):  @ org.apache.harmony.luni.internal.net.www.protocol.http.httpurlconnectionimpl.getin$ 07-18 15:43:44.836: w/system.err(545):  @ uk.co.redfruit.libraries.srpdb.srpdbclient.getcontent(srpdbclient.java:106) 07-18 15:43:44.836: w/system.err(545):  ... 13 more 

i'm aware of bug appears make happen in android 4.x+, same error when running in gingerbread.

the code causes error follows:

stringbuilder stringbuilder = null;         try {             url url = new url(targeturl);             httpurlconnection connection = (httpurlconnection) url.openconnection();             connection.setrequestmethod("get");             connection.connect();             bufferedreader reader = new bufferedreader(new inputstreamreader(                     connection.getinputstream()));             stringbuilder = new stringbuilder();             string content = null;             while ((content = reader.readline()) != null) {                 stringbuilder.append(content + "\n");             }             reader.close();         } catch (ioexception e) {             throw new srbclientexception(e);         } 

i have internet permission in manifest , url exist - can access in browser. can see i'm going wrong or i'm missing?

update: tried using basic http client attempted workaround. didn't work, provided different error. showed getting 403, which, in previous attempt, resulted in filenotfound, time caused json exception html error message returned couldn't (obviously) parsed json.

i'm guessing server side issue, although i'm baffled why 403 in android, in no other context...

it turns out server blocking whatever default user agent (nothing perhaps?) , returning 403.

by setting standard browser user agent (in case used chrome) worked.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -

c# - String.format() DateTime With Arabic culture -