如何在不使用第三方工具的情况下通过android调用Webmethods

时间:2011-06-21 06:47:57

标签: android

我创建了 .net webservice方法 authenticateuser,需要从 Android 应用程序中调用它。如何在不使用第三方工具的情况下完成?

1 个答案:

答案 0 :(得分:1)

如果要调用.net Web服务并使用POST方法,请按照以下步骤操作:

 DefaultHttpClient  httpclient = getClient();

  HttpPost httppost = new HttpPost("complete address");

  List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);//number should be the amount of parameters 

   nameValuePairs.add(new BasicNameValuePair("param_name", "param_value"));
   nameValuePairs.add(new BasicNameValuePair("param_name", "param_value"));

    try {
        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        HttpResponse response = httpclient.execute(httppost);
        HttpEntity ht = response.getEntity();

        BasicResponseHandler myHandler = new BasicResponseHandler();
                String endResult = "";

            endResult = myHandler.handleResponse(response); 

            System.out.println("endResuilt*** = "+endResult);

            dataStream = endResult;
        }catch(Exception e){
           //Catch the Exception
        }

希望这有帮助!