Results 1 to 8 of 8
Thread: Get Request Problem In Android
- 07-26-2011, 02:04 AM #1
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
Get Request Problem In Android
I use Eclipse and when I try to connect to my servlet using 'normal' Java, it works fine.
But when I paste the same code in my Android project, I get an empty String as a response.
Why ?
Code: (BASE_URL = url before (including) the '?' , inputURL is the rest of the URL)
private static String accessURL(String inputURL) throws IOException{
String inputLine = "";
try {
URL oracle = new URL(BASE_URL + inputURL);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream()));
inputLine = in.readLine();
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} finally{
return inputLine;
}
}
And calling the function:
accessURL("type=1");
- 07-26-2011, 02:33 AM #2
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
What says the logcat ? Do you get an exception? Granted the right uses-permission in the AndroidManifest? <uses-permission> | Android Developers
- 07-26-2011, 01:45 PM #3
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
logcat = console window ? No error there,
No exception.
When I debug the servlet, it acts as if ... no one is accessing it, therefore the problem is totally in Android..
I pasted - <uses-permission android:name="string" /> - in my AndroidManifest, nothing changes..
How do I set permission to the web , and use the returned String ?
- 07-26-2011, 02:39 PM #4
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
No -> logcat | Android Developers (in eclipse ddms perspective)
I pasted - <uses-permission android:name="string" /> - in my AndroidManifest, nothing changes..
- no you have to replace "string" with the right permission :D --> <uses-permission android:name="android.permission.INTERNET"></uses-permission>
- 07-26-2011, 03:54 PM #5
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
Thanks for your answer,.. but
I did add the permission.INTERNET:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="comm.androidmonopoly"
android:versionCode="1"
android:versionName="1.0">
<uses-sdk android:minSdkVersion="12" />
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".AndroidMonopolyActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
And used this code: (And it throws an exception at line ** )
private static String accessURL(String inputURL) throws IOException{
String inputLine = "";
try {
URL oracle = new URL(BASE_URL + inputURL);
URLConnection yc = oracle.openConnection();
BufferedReader in = new BufferedReader(new InputStreamReader(yc.getInputStream())); **
inputLine = in.readLine();
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} finally{
return inputLine;
}
}
- 07-26-2011, 04:09 PM #6
Senior Member
- Join Date
- Oct 2010
- Location
- Germany
- Posts
- 780
- Rep Power
- 4
And used this code: (And it throws an exception at line ** )
and which exception.....??
- 07-26-2011, 04:35 PM #7
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
URL oracle = new URL(BASE_URL + inputURL);
URLConnection yc = oracle.openConnection();
InputStream iS = yc.getInputStream(); <--- Here it throws the exception
InputStreamReader iSR = new InputStreamReader(iS);
BufferedReader in = new BufferedReader(iSR);
inputLine = in.readLine();
- 07-26-2011, 08:25 PM #8
Member
- Join Date
- Jun 2011
- Posts
- 8
- Rep Power
- 0
Similar Threads
-
[XML-RPC Apache] The api create request handler for each request! HELP
By dario in forum Advanced JavaReplies: 0Last Post: 07-06-2011, 01:12 PM -
Android Help
By fresh83 in forum AndroidReplies: 1Last Post: 05-19-2011, 08:44 PM -
problem in understanding request.setAttribute() method
By jnjh in forum New To JavaReplies: 1Last Post: 05-10-2011, 08:10 AM -
problem with ServletRequest request.getInputStream
By bbq in forum Java ServletReplies: 2Last Post: 02-27-2011, 10:50 AM -
android sdk
By aizen92 in forum AndroidReplies: 2Last Post: 02-21-2011, 10:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks