1

I want to get json info from the link: http://android.forum-example.org/?a=1&b=2&c=3

but Log.v tells me that after request.setEntity(new UrlEncodedFormEntity(qparams)); my URI is: http://android.forum-example.org/?

Where is my mistake?

code:

try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpPost request = new HttpPost("http://android.forum-example.org/?");
    List<NameValuePair> qparams = new ArrayList<NameValuePair>(3);
    qparams.add(new BasicNameValuePair("a", "1"));
    qparams.add(new BasicNameValuePair("b", "2"));
    qparams.add(new BasicNameValuePair("c", "3"));
    request.setEntity(new UrlEncodedFormEntity(qparams));
    Log.v("URI:", request.getURI().toString());
    HttpResponse response = httpClient.execute(request);
    } catch (IOException e) { e.printStackTrace(); }
Sviatoslav
  • 1,301
  • 2
  • 17
  • 42

2 Answers2

2

You are trying to make a POST request.. but the url is of type GET request

look here : How to add parameters to a HTTP GET request in Android?

Community
  • 1
  • 1
Gaurav Shah
  • 5,223
  • 7
  • 43
  • 71
1

Use HttpGet instead of HttpPost:

try {
    HttpClient httpClient = new DefaultHttpClient();
    HttpGet request = new HttpGet("http://android.forum-example.org/?a=1&b=2&c=3");
    Log.v("URI:", request.getURI().toString());
    HttpResponse response = httpClient.execute(request);
} catch (IOException e) {
    e.printStackTrace();
}
Caner
  • 57,267
  • 35
  • 174
  • 180