HttpPost give IO error

Problems with WiFi, SQLite ,Bluetooth, WiMax, Proxies, etc...

HttpPost give IO error

Postby Wubinator » Fri Apr 24, 2009 9:35 pm

Hi all,

I just started with Android today and I try to get information from a site based on an available API. I tried the URL in a browser and it is correct, but when I try to connect with a HttpPost it fails on a IOException on the line: "this.response = client.execute(post);"

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2.  
  3.         public void onCreate(Bundle savedInstanceState) {
  4.  
  5.                 super.onCreate(savedInstanceState);
  6.  
  7.  
  8.  
  9.                 // Create a http connection
  10.  
  11.                 HttpClient client = new DefaultHttpClient();
  12.  
  13.                 HttpPost post = new HttpPost(URL_ROOT + CHARACTER_SHEET);
  14.  
  15.  
  16.  
  17.                 try {
  18.  
  19.                         List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
  20.  
  21.                         // Your DATA
  22.  
  23.                         nameValuePairs.add(new BasicNameValuePair("userId", USER_ID));
  24.  
  25.                         nameValuePairs.add(new BasicNameValuePair("apiKey", API_KEY));
  26.  
  27.  
  28.  
  29.                         post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
  30.  
  31.  
  32.  
  33.                         this.response = client.execute(post);
  34.  
  35.  
  36.  
  37.                         ConnectionEventHandler responseEvent = new ConnectionEventHandler(
  38.  
  39.                                         this);
  40.  
  41.                 } catch (ClientProtocolException e) {
  42.  
  43.                         // TODO Auto-generated catch block
  44.  
  45.                         e.printStackTrace();
  46.  
  47.                 } catch (IOException e) {
  48.  
  49.                         // TODO Auto-generated catch block
  50.  
  51.                         e.printStackTrace();
  52.  
  53.                 }
  54.  
  55.                
  56.  
  57.                 this.setContentView(R.layout.main);
  58.  
  59.         }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


The url should be end up something like http:x.com/bla.aspx?userId=1234&apiKey=48BkS4t

Thanks for the help,
Rick
Wubinator
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Apr 24, 2009 9:24 pm
Location: Amsterdam

Top

Postby Moons » Sat Apr 25, 2009 8:39 pm

Maybe you could give us more information about the Exception thrown
Moons
Developer
Developer
 
Posts: 25
Joined: Fri Feb 13, 2009 9:19 pm

Postby Wubinator » Mon Apr 27, 2009 6:53 pm

Somehow I never see a stacktrace, but in the debugger the detailMessage of 'e' it just says "unknown error"
Wubinator
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Apr 24, 2009 9:24 pm
Location: Amsterdam

Postby Wubinator » Mon Apr 27, 2009 7:43 pm

I think I found the solution .... inside the AndroidManifest.XML I have to set a permission to access the Internet

<uses-permission android:name="android.permission.INTERNET"></uses-permission>
Wubinator
Junior Developer
Junior Developer
 
Posts: 12
Joined: Fri Apr 24, 2009 9:24 pm
Location: Amsterdam

Top

Return to Networking & Database Problems

Who is online

Users browsing this forum: No registered users and 9 guests