Reputation: 1739
I have a url which serves data to my android application, i learnt from a tutorial and wrote some code. It works perfectly for other url's but this one
http://acolyteserv.appspot.com/Products/getProductMatchedList/?format=json&p0=galaxy&p1=4&p2=all
the code is:
private void testere()
{
InputStream is = null;
String result;
try{
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://acolyteserv.appspot.com/Products/getProductMatchedList/?format=json&p0=galaxy&p1=4&p2=all");
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
is = entity.getContent();
try{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
result=sb.toString();
Toast t=Toast.makeText(getApplicationContext(), result, Toast.LENGTH_LONG);
t.show();
}catch(Exception e){
Log.e("log_tag", "Error converting result "+e.toString());
}
}
catch(Exception e){
Log.e("log_tag", "Error in http connection "+e.toString());
}
}
If i use this URL the toast, result gives me an empty string, but if I use the example URL like
http://api.geonames.org/earthquakesJSON?north=44.1&south=-9.9&east=-22.4&west=55.2&username=demo
Please tell me what I'm doing wrong here, i'm new to JSON and the whole web service world.
Upvotes: 0
Views: 141
Reputation: 23972
Add your request params to your HttpEntity. Or use HttpGet instead
Upvotes: 1
Reputation: 38727
You are using HttpPost
, but not submitting any entity with the request.
Try using HttpGet
instead. Given the names of the things in your URL etc, I suspect a GET is what you actually want.
Upvotes: 1