Milap Pancholi
Milap Pancholi

Reputation: 134

pass two parameter to webservice using android

params[0] store a user of webservice created in .net framework. so in my web method have two parameter "StartIndex" and "EndIndex" so now how can i pass a parameter to Web method in android.

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost( params[0]);
    HttpResponse response = client.execute(post);

Upvotes: 1

Views: 1390

Answers (1)

Gorcyn
Gorcyn

Reputation: 2817

You can use a NameValuePair list to put multiple parameters to your POST request, as in :

try {
    HttpPost httpPost = new HttpPost("url");
    List<NameValuePair> parameters = new ArrayList<NameValuePair>(2);  
    parameters.add(new BasicNameValuePair("login", "trout"));  
    parameters.add(new BasicNameValuePair("password", "salmon"));  
    httpPost.setEntity(new UrlEncodedFormEntity(parameters, "UTF-8"));

    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse httpResponse = httpClient.execute(httpPost);

    String response = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
} catch (UnsupportedEncodingException e) {

} catch (ClientProtocolException e) {

} catch (IOException e) {

}

Upvotes: 3

Related Questions