September 4th, 2012, 10:40 AM
|
#3 (permalink)
|
|
Junior Member
Thread Author (OP)
Join Date: Nov 2011
Posts: 31
Device(s):
Carrier: Not Provided
Thanks: 1
Thanked 0 Times in 0 Posts
|
Ok, I made the connection through httppost:
But when I run my app, it just crashes from the beginning...
Code:
// http post
InputStream inputStream = null;
String result = null;
try {
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams());
HttpPost httppost = new HttpPost("http://www.webmention.com/bosshunting.php");
// Depends on your web service
httppost.setHeader("Content-type", "application/json");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
}
// convert response
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
result = sb.toString();
} catch (Exception e) {
Log.e("log_tag", "Error converting result " + e.toString());
}
// parse json data
try {
JSONArray jArray = new JSONArray(result);
ArrayList imageUrls = new ArrayList();
for (int i = 0; i < jArray.length(); i++) {
JSONObject json_data = jArray.getJSONObject(i);
imageUrls.add(json_data.getString("url"));
}
} catch (JSONException e) {
Log.e("log_tag", "Error parsing data " + e.toString());
}
I try to get an arraylist imageUrls of titleone, titletwo, titlethree
|
|
|