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);"
Using java Syntax Highlighting
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- // Create a http connection
- HttpClient client = new DefaultHttpClient();
- HttpPost post = new HttpPost(URL_ROOT + CHARACTER_SHEET);
- try {
- List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
- // Your DATA
- nameValuePairs.add(new BasicNameValuePair("userId", USER_ID));
- nameValuePairs.add(new BasicNameValuePair("apiKey", API_KEY));
- post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
- this.response = client.execute(post);
- ConnectionEventHandler responseEvent = new ConnectionEventHandler(
- this);
- } catch (ClientProtocolException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- this.setContentView(R.layout.main);
- }
Parsed in 0.012 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