1

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);

1 Answer 1

3

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) {

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.